Re: empty() and SplFixedArray

From: Date: Thu, 25 Dec 2014 03:52:39 +0000
Subject: Re: empty() and SplFixedArray
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-324158@lists.php.net to get a copy of this message
On Wed, Dec 24, 2014 at 10:29 PM, Michael Rubin <mrubin@iraxef.com> wrote: > I've been converting some code from using array to SplFixedArray and I ran > into a gotcha - empty(array()) returns true whereas empty(new > SplFixedArray()) returns false. > > Is this considered a bug? > Emptiness is a matter of definition when it comes to objects. I guess that is why objects will never pass the empty() test regardless (even with a new stdClass) in PHP. Arrays on the other hand are simpler than objects (I like to think of them as a collection of variables) which you can easily check if the collection is empty or not. A fast way to check would be empty ((array) $object) - which only works on PHP >= 5.5.

« previous php.general (#324158) next »