简体   繁体   中英

PHP count(): Parameter must be an array or an object that implements Countable

Here is a snippet of my code in the file public_html/wp-content/themes/arabv3/CustomMetaBox/CMB2.php , starting at line 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;
    }

When I run the code I get the following error:

PHP Warning: count(): Parameter must be an array or an object that implements Countable in

Your PHP version ? if its 7.2 then count function give you error when you count stdclass .

Example:

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

echo count($count_value);

//this give an error in case of php 7.2 version

you can typecast to an array or make that stdclass as an array .

you can check php doc :-

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM