After updating to PHP 7.2 from PHP 7.0 the following warning is shown when using Devel:

Warning: count(): Parameter must be an array or an object that implements Countable in krumo::_object() (line 1123 of /var/aegir/platforms/drupal-7.58/sites/SITE/modules/devel/krumo/class.krumo.php).

Maybe the core 7.2 compatibility patch #2947772: Fully support PHP 7.2 in Drupal 7 or the Drupal 8 issue #2951821: Warning: count(): Parameter must be an array could help?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

NWOM created an issue. See original summary.

salvis’s picture

Component: krumo » devel
Status: Active » Needs review
FileSize
1.78 KB

Yes, count() expects an array. I don't think the Countable interface is a consideration here.

I also found another instance of count() potentially getting a non-array, as well as an undefined index, both outside of krumo, but related to dpm() et al.

salvis’s picture

After giving this some more thought, here's an improved patch.

NWOM’s picture

Status: Needs review » Reviewed & tested by the community

#3 worked great and applied cleanly. Thank you very much!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 3: devel-php72-count-bugs-2959508-3-D7.patch, failed testing. View results

salvis’s picture

  • salvis committed bd4061f on 7.x-1.x
    Issue #2959508 by salvis: Fix PHP 7.2 Incompatibility - count():...
salvis’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

MustangGB’s picture

So this has added is_array(), I'm wondering if instead we should be duplicating the code from merits_krumo() and using (is_object($input) || is_array($input)) instead?

salvis’s picture

Given is_object($input) == TRUE, how likely is it that $input implements Countable? And even if it does, what would this give to us?

Granted, the patch is on the efficient side rather than on the sophisticated side, but do you see any relevant use case for change?

coozila’s picture

another error similar to the latest version drupal 7.9+ php 7.4-fpm + nginx and memcached server:

Warning: count(): Parameter must be an array or an object that implements Countable in _object() (line 1111 of /var/www/mysite.com/web/sites/all/modules/devel/krumo/class.krumo.php).

this error is always present in the logs even though everything is updated with the composer, any suggestion is welcome

1111  <?php if (count($data)) { 
1112   krumo::_vars($data); 
1113    } ?>