As stated above, empty()
does not consider count($obj) == 0
"empty". The reason for this does not work as expected, because arrays do not implement Countable
ie
array() instanceof Countable
Probably the obvious workaround, but I would decide to post it here.
function is_empty ($val) { return empty($val) || ($val instanceof Countable && empty(count($val))); }
Example:
class Object implements Countable { protected $attributes = array();
I should note that this solution works in my case, because I would already define is_empty()
for prettiness along with other is_*
methods.
source share