Fix strict count() behavior in PHP 7.2

This commit is contained in:
Kijin Sung 2017-12-01 01:42:03 +09:00
parent 6f7f92f3e2
commit 6f35f5bafc
7 changed files with 43 additions and 16 deletions

View file

@ -517,6 +517,28 @@ function tobool($input)
return (bool)$input;
}
/**
* Counts members of an array or an object.
*
* @param mixed $array_or_object
* @return int
*/
function countobj($array_or_object)
{
if (is_array($array_or_object))
{
return count($array_or_object);
}
elseif (is_object($array_or_object))
{
return count(get_object_vars($array_or_object));
}
else
{
return @count($array_or_object);
}
}
/**
* Checks if the given string contains valid UTF-8.
*