Magento 2 Warning – Count Parameter Must Be Array or Object

magento2php-7.2

I have this code:

public function getCounter()
    {
        /** @var \Amasty\ShopbyPage\Model\Page $model */
        $model = $this->_coreRegistry->registry(RegistryConstants::PAGE);
        return count($model->getConditions());
    }

But in line:

return count($model->getConditions());

I get error in php 7.2:

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

Magento 2.3 version. PHP7.2

In php 7.1 works fine.
How can I fix it?

Best Answer

Remove count and return direct $model->getConditions() add print_r and check what result you are getting. You will know what you have to do after that

Related Topic