If you do empty() on an array with no elements in it, you get true. However, if you do empty() on a Countable object with a count of 0 then you get false. It seems to me a 0 count Countable should be considered empty. Am I missing something?
<?php
class Test implements Countable
{
public $count = 0;
public function count ()
{
return intval (abs ($this -> count));
}
}
$test = new Test ();
var_dump (empty ($test));
var_dump (count ($test));
$test -> count = 10;
var_dump (empty ($test));
var_dump (count ($test));
I would have expected the first call to empty to return true, but it doesn’t.
Is there a reasonable reason for this to be the case, or is it a bug?
From the docs:
I think
$testin your case is still considered anObject, which is not in the list of what empty would return asTRUE