简体   繁体   中英

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

i've a problem with Wordpress. This is the error message: PHP 7.2 Warning count(): Parameter must be an array or an object that implements Countable /web/htdocs/www.firenzeflowershow.com/home/wp-content/themes/wpex-elegant/functions/meta/init.php on line 750

> elseif ( is_array( $meta_box['pages'] ) && count( $meta_box['pages']
> === 1  ))             $type = is_string( end( $meta_box['pages'] ) ) ? end( $meta_box['pages'] ) : false;

The closing parenthesis of count is in the wrong position. You are actually passing a boolean to the function, because " $meta_box['pages'] === 1 " will return true or false. Your code should be:

count($meta_box['pages']) === 1

Please try if this works:

elseif ( is_array( $meta_box['pages'] ) && count($meta_box['pages'])
>= 1  )

Try:

elseif ( is_array( $meta_box['pages'] ) && count( $meta_box['pages'] )
=== 1)             $type = is_string( end( $meta_box['pages'] ) ) ? end( $meta_box['pages'] ) : false;

Your code did not work because === 1 was inside the count() function call: count($meta_box['pages'] === 1) , and a comparison returns a bool . Here, I have changed it to count($meta_box['pages']) === 1 which gets the number of elements in the array, and checks if it returns 1.

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