[PHP 7.2] My fix for «Warning: count(): Parameter must be an array or an object that implements Countable in lib/internal/Magento/Framework/View/Design/Theme/ThemeList.php on line 237»

php7
bug
bug-fix
php72
php72-count
(Dmitry Fedyuk) #1

Running data recurring… Warning: count(): Parameter must be an array or an object that implements Countable in lib/internal/Magento/Framework/View/Design/Theme/ThemeList.php on line 237

I have encountered this issue in a bin/magento setup:upgrade response after upgrading PHP to 7.2.

0 Likes

[PHP 7.2] My fix for «Warning: count(): Parameter must be an array or an object that implements Countable in Magento/Wishlist/Observer/AddToCart.php on line 79»
[PHP 7.2] My fix for «Warning: count(): Parameter must be an array or an object that implements Countable in Magento/Theme/Block/Html/Topmenu.php on line 241»
[PHP 7.2] My fix for «Warning: count(): Parameter must be an array or an object that implements Countable in Magento/Backend/Block/Menu.php on line 390»
[PHP 7.2] My fix for «Warning: sizeof(): Parameter must be an array or an object that implements Countable in app/code/Magento/Sales/view/adminhtml/templates/order/totalbar.phtml on line 10»
(Dmitry Fedyuk) #2

The «Changelog» section of the PHP count() function specification says:

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

http://php.net/manual/en/function.count.php#refsect1-function.count-changelog

0 Likes

(Dmitry Fedyuk) #3

«PHP RFC: Counting of non-countable objects» says:

Calling count() on a scalar or object that doesn’t implement the Countable interface returns 1.
There are no known use cases for this, and it can easily hide bugs <…>.
<…>
This RFC proposes adding a warning when calling count() with a parameter that is a scalar, null, or an object that doesn’t implement Countable.

0 Likes

(Dmitry Fedyuk) #4

3v4l.org/YecYW

0 Likes

(Dmitry Fedyuk) #5

My fix

You need to patch the Magento\Framework\View\Design\Theme\ThemeList::_prepareConfigurationData() method.

Replace the line:

with the following one:

if ($parentPathPieces && count($parentPathPieces) == 1) {
1 Like

(Dmitry Fedyuk) #6

See also

0 Likes

(Dmitry Fedyuk) #7

It is fixed at 2018-01-25 in the Magento 2.3 development branch:

0 Likes

(Bhavesh Zyelon) #8

Thank it’s working :slight_smile:

0 Likes