使用最新WPJAM升级PHP7.2以上,出现Warning: count():问题
使用最新WPJAM,需要PHP7.2以上版本,升级PHP后,有其他功能插件(插件是好插件就是3年没有更新了)提示如下警告在前台页面:
Warning: count(): Parameter must be an array or an object that implements Countable in ……………….php on line 1234
出现这个问题的原因是PHP7.2以后,count函数仅支持参数为数组或者 Countable对象, 否则将报警告。
下面仅以我遇到的个例说一下解决办法。
根据提示找到问题行:
$savedusers = get_post_meta($post->ID, 'U_S_C_users',true);
if (!count($savedusers) > 0 && !count($savedroles) > 0 ){
return $content;
}
$savedusers这个参数不是数组也不是Countable对象,我们就直接将count()里的参数变成数组形式,粗暴修改为:
$savedusers = get_post_meta($post->ID, 'U_S_C_users',true);
if (!count($savedusers? : []) > 0 && !count($savedroles? : []) > 0 ){
return $content;
}
解决!
参考文章:https://core.trac.wordpress.org/ticket/43368
1条回复
我要回复
暂时不支持网页回复,请安装