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!)