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

Time:02-12

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;

CodePudding user response:

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

CodePudding user response:

Please try if this works:

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

CodePudding user response:

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.

  • Related