Re: Boolean-cast and arrays

From: Date: Thu, 08 Feb 2007 17:36:37 +0000
Subject: Re: Boolean-cast and arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-248595@lists.php.net to get a copy of this message
Tim wrote:
First thank you all for your input on "all-in-one" classes. Reading the php manual on boolean types and casts, and came accros the following: <quote> When converting to boolean, the following values are considered FALSE: ... an array with zero elements ... </quote> So here I am sitting and wondering if after all this while doing: $arr = array(); If (count($arr) == 0) {} Shouldn't have been simply doing: $arr = array(); If (!arr) {}
I'm afraid I can't bring in any insight, I just wanted to mention that's a nice "feature" you've brought up. The only issue I can see popping up is that !$arr doesn't explicitly indicate that you are checking for an empty array ... Other than that, I guess it's yet another way to get of a few bytes worth of code. I'm curious to find out what others have to say.
Is the latter problematic in any programming standards? Does it take longer to process? Is it using count()? Is "Type-Juggling" considered good practise? Regards, Tim


« previous php.general (#248595) next »