I found a question in php7.3.4
.
if ( count( '' ) == 1 )
{
echo 1;
} else {
echo 2;
}
This program output 1.Then I checked the source for the function 'count'.
PHP_FUNCTION(count)
{
....
switch (Z_TYPE_P(array)) {
case IS_NULL:
php_error_docref(NULL, E_WARNING, "Parameter must be an array or an object that implements Countable");
RETURN_LONG(0);
break;
case IS_ARRAY:
...
break;
case IS_OBJECT:
....
break;
default:
php_error_docref(NULL, E_WARNING, "Parameter must be an array or an object
that implements Countable");
RETURN_LONG(1);
break;
}
This is easy to producing BUG.
I think it count('')
maybe output error or 0 is better than 1 and a Warning.
What do you think about?
And count(NULL)
is not equal to count('')
,It feels strange.