I discourage the use of empty(), it can leads to so many potential mistakes that is better to simply never use it.
The only mistake it can lead to is if there's a typo in a variable name, but in cases like this:
function myfunc( array $var ) { if( empty( $var ) )
I highly doubt there's a chance of running into a typo or mistake.
If I wanted to check an array is empty I would probably:
count( $array ) === 0
cheers,
count() requires determining the size of the array, which is significantly slower than any of the solutions.
*--* *Tyler Romeo* Stevens Institute of Technology, Class of 2015 Major in Computer Science www.whizkidztech.com | tylerromeo@gmail.com
On Wed, Feb 6, 2013 at 5:06 PM, Antoine Musso hashar+wmf@free.fr wrote:
Le 06/02/13 22:22, Tyler Romeo a écrit :
So basically here's my goal (it's the same as if ( v. if( ). I don't care about reaching consensus on either side, because such an attempt is
futile.
I prefer unless( !$foo ) but that is just me.
The only thing I want to at least get some support on is that a given patchset should not be blocked from merging just because it uses empty()
in
a place where it's obviously OK to use it (for example, when you're checking if a function argument is empty one line below the beginning of the function).
I discourage the use of empty(), it can leads to so many potential mistakes that is better to simply never use it.
If I wanted to check an array is empty I would probably:
count( $array ) === 0
cheers,
-- Antoine "hashar" Musso
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l