[英]Countable issue for PHP 7.2
I have a client that's been relying on a WP plugin for years that was abandoned by the author a few years ago. 我有一个客户多年来一直依赖WP插件,而该插件几年前就被作者放弃了。 I've been able to make some fixes to make it work with an upgrade to PHP 7.2, but this one puzzles me.
我已经能够进行一些修复以使其能够升级到PHP 7.2,但这使我感到困惑。 The more I research it, I feel like the less I understand about how to fix it.
我研究得越多,就越不了解如何解决它。
Warning below: 以下警告:
Warning: count(): Parameter must be an array or an object that implements Countable in /app/public/wp-content/plugins/ozh-admin-drop-down-menu/inc/core.php on line 311 ( first line below is 311 )
警告:count():参数必须是第311行( 第一行 /app/public/wp-content/plugins/ozh-admin-drop-down-menu/inc/core.php中实现Countable的数组或对象) 下面是311 )
if (!count($wp_ozh_adminmenu)) {
$wp_ozh_adminmenu = (array)get_option('ozh_adminmenu');
unset($wp_ozh_adminmenu[0]);
}
Before PHP 7.2 when passing a non-array to count()
, it returned 1. 在PHP 7.2之前,将非数组传递给
count()
,它返回1。
Now, as you can see in the breaking changes , count()
emits a warning when you give it a non-array. 现在,您可以在重大更改中看到,当您给它一个非数组时,
count()
会发出警告。
A simple workaround is to check if it's an array before using it. 一个简单的解决方法是在使用它之前检查它是否为数组。 It may require a bit more checks, if you want to allow arrays and string for example.
例如,如果要允许数组和字符串,则可能需要更多检查。
<?php
if (!is_array($wp_ozh_adminmenu) || !count($wp_ozh_adminmenu)) {
$wp_ozh_adminmenu = (array)get_option('ozh_adminmenu');
unset($wp_ozh_adminmenu[0]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.