0

Getting this error when trying to complete upgrade of Mgaento 2.2.2 (running on PHP7.1) to Magento 2.3.1 (running on PHP 7.2)

1 exception(s): Exception #0 (Exception): Warning: count(): Parameter must be an array or an object that implements Countable in /home/mytheme/public_html/app/design/frontend/Sm/topshop/Sm_Deals/templates/default.phtml on line 16

I managed to fix a lot of errors with researching but stuck with this one.

$start = ($start <= 0 || $start > count($list)) ? 0 : $start - 1;
1
  • It seems that the variable you are passing to the count function it should be an array or an object but either it is not an array or it doesn't contains any value into it (means it is normal variable with assignment of empty value). – Abhishek Tripathi Aug 5 '19 at 4:45
0

As of PHP 7.2 this is a warning about a non-Countable object being passed to count():

count() will now yield a warning on invalid countable types passed to the array_or_countable parameter.

Without any further code to look at (e.g. the code that defines the $list variable) or knowing what $list contains, I would guess that however $list is defined one of the valid results is null. You have two options:

  1. Check the value of $list before that line and redefine it if necessary:
if(!is_array($list) || !($list instanceof \Countable) {
    $list = [];
}
  1. Find out how $list is defined and fix it so it returns only an array or an object that implements the Countable interface.
0

It seems that the variable you are passing to the count function it should be an array or an object but either it is not an array or it doesn't contains any value into it (means it is normal variable with assignment of empty value).

In this case what you can do the following things.

1.Search for the initialization of the variable $list & just above it define it as an array something like this

$list = []; //Best & Magento defined Way
or
$list = array(); //Normal way

2.Make sure while initializing the variable $list the content you are assigning to it should be an object or an array & contains value in it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.