Jump to content

Warning: sizeof(): Parameter must be an array or an object that implements Countable


Recommended Posts

Hello friends, I have the following problem, when I see the articles that I have saved as favorites I see the following message:

Warning: sizeof(): Parameter must be an array or an object that implements Countable in /var/www/ blockwishlist/managewishlist.php on line 102

If I can see the products but that message appears, I hope you can help me, thank you.

 

image.thumb.png.66fbb28ed81e30331429b22219f91a5d.png

Edited by Ana22 (see edit history)
Link to comment
Share on other sites

  • 1 year later...
On 9/7/2020 at 7:56 PM, Ana22 said:

Hello friends, I have the following problem, when I see the articles that I have saved as favorites I see the following message:

Warning: sizeof(): Parameter must be an array or an object that implements Countable in /var/www/ blockwishlist/managewishlist.php on line 102

If I can see the products but that message appears, I hope you can help me, thank you.

 

image.thumb.png.66fbb28ed81e30331429b22219f91a5d.png

Starting PHP 7.2, sizeof() ( or count() ) can only count arrays or countable objects, not being able to count, for example, strings, true or false booleans, empty or null variables. Please check line 102 and below in your managewishlist.php file and trace the object or variable it's trying to reach. If it's not a countable element it will return an error. You could either rollback your server's PHP version, or adapt the code.

Link to comment
Share on other sites

  • 6 months later...
On 9/7/2020 at 7:56 PM, Ana22 said:

Hello friends, I have the following problem, when I see the articles that I have saved as favorites I see the following message:

Warning: sizeof(): Parameter must be an array or an object that implements Countable in /var/www/ blockwishlist/managewishlist.php on line 102

If I can see the products but that message appears, I hope you can help me, thank you.

I hope PS authors already fixed this long time ago.

But for those who experiencing similar error message..

SOLUTION 1:

on: https://github.com/PrestaShop/PrestaShop/pull/9358/files
is solution how to adapt old code for new PHP on many pages, just you have to understand principle (do not copy/paste automatically!):

OLD CODE:

if (isset($this->_list['addons']) && count($this->_list['addons'])) {

NEW CODE:

if ($this->isCountableAndNotEmpty($this->_list, 'addons')) {

Plus add new function into same file, or implement generally through override something:

/**
* Check if key is present in array, is countable and has data.
*
* @param array $array Array
* @param string $key Key
*
* @return boolean
*/
protected function isCountableAndNotEmpty(array $array, $key)
{
return isset($array[$key]) &&
(
$array[$key] instanceof Countable ||
is_array($array[$key])
) &&
count($array[$key]);
}

 

SOLUTION 2:

I´ve found couple handy shorter solutions like:
 

if (is_array($children) && sizeof($children) <= 0) {

or:

if ( (is_array($children) || $children instanceof \Countable) && sizeof($children) > 0) {

but still pay atention - you have to understand principle (do not copy/paste automatically!)

Edited by janoo
new ideas (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...