PHP count():参数必须是实现Countable的数组或对象

时间:2019-03-12 19:21:38

标签: php count

这是文件中我的代码的摘录 public_html / wp-content / themes / arabv3 / CustomMetaBox / CMB2.php ,从565行开始

        // if it's an array of one, extract it
    elseif ( is_array( $this->prop( 'object_types' ) ) && count( $this->prop( 'object_types' ) === 1 ) ) {
        $cpts = $this->prop( 'object_types' );
        $type = is_string( end( $cpts ) )
            ? end( $cpts )
            : false;
    }

运行代码时,出现以下错误:

  

PHP警告:count():参数必须是在

中实现Countable的数组或对象

1 个答案:

答案 0 :(得分:0)

您的PHP版本?如果它的7.2那么count函数在计算stdclass时给您错误。

示例:

$count_value = stdClass Object( [asset_id] => 234 [parent_asset_id] => '');

echo count($count_value);

//这在php 7.2版本的情况下会报错

您可以将类型转换为数组,或将该stdclass设置为数组。

您可以检查php doc:-

https://www.php.net/manual/en/migration72.incompatible.php#migration72.incompatible.warn-on-non-countable-types

相关问题