PHP 7.2 - count(): Parameter must be an array or an object that implements Countable
Abraham-Tourdex opened this issue · 5 comments
Abraham-Tourdex commented
I'm getting this error on a new install of PHP 7.2. I'm getting it in phpmyadmin as well just fyi:
Warning: count(): Parameter must be an array or an object that implements Countable in var/www/html/iconcierge/shared/krumo/class.krumo.php on line 1132
Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/html/iconcierge/shared/krumo/class.krumo.php on line 1133
Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/html/iconcierge/shared/krumo/class.krumo.php on line 1146
it is coming from this block of code:
/**
* Render a dump for an object
*
* @param mixed $data
* @param string $name
*/
private static function _object(&$data, $name)
{
?>
<li class="krumo-child">
<div <?php if (count($data) > 0) {?> onClick="krumo.toggle(this);"<?php } ?>
class="krumo-element<?php echo count($data) > 0 ? ' krumo-expand' : '';?>" >
<a class="krumo-name"><?php echo $name;?></a>
(<em class="krumo-type">Object</em>)
<strong class="krumo-class"><?php echo get_class($data);?></strong>
<?php
if( get_class( $data ) == 'Image' ){
echo '<img class=img-thumbnail src="' . $data->urlSecure . '" />';
}
?>
</div>
<?php if (count($data))
{
self::_vars($data);
} ?>
</li>
<?php
}
Namely the two calls to count($data)
.
Casting $data
to an array causes more bugs. Ideas?
yayabla commented
Change your code to this.
`private static function _object(&$data, $name)
{
?>
<div <?php if ((is_object($data) && count(get_object_vars($data)) > 0) || count($data) > 0) {?> onClick="krumo.toggle(this);"<?php } ?>
class="krumo-element<?php echo (is_object($data) && count(get_object_vars($data)) > 0) || count($data) > 0 ? ' krumo-expand' : '';?>" >
<a class="krumo-name"><?php echo $name;?></a>
(<em class="krumo-type">Object</em>)
<strong class="krumo-class"><?php echo get_class($data);?></strong>
</div>
<?php if ((is_object($data) && count(get_object_vars($data)) > 0) || count($data))
{
self::_vars($data);
} ?>
</li>
<?php
}`
Kashiffrq commented
if ( is_array( $data) ) {
if ( $data > count( $data) ) // if the requested data doesn't exist
$data = count( $data); // give them the highest numbered data that DOES exist
} else {
$data= 0;
}
kktsvetkov commented
Casting
$data
to an array causes more bugs. Ideas?
This is used to render objects, so it should not be converted to array. The suggestion from @yayabla to use get_object_vars($data)
is the best approach
kktsvetkov commented
Issue is fixed in 0.4.1
ZakiBelhadj commented
Try this Solution:
if ( count( $_posts )) {
....
}
Add "is_array($_posts) &&" to become:
if (is_array($_posts) && count($_posts) ) {
....
}