[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»

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.

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

«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.

3v4l.org/YecYW

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

See also

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

Thank it’s working :slight_smile:

A post was split to a new topic: «i just copy pasted u r codein the middle now it shows Undefined variable: parentPathPieces»