NYCPHP Meetup

NYPHP.org

[nycphp-talk] ${$variable}

John Lacey jlacey at ix.netcom.com
Wed Aug 27 18:46:26 EDT 2003


Analysis & Solutions wrote:

>On Wed, Aug 27, 2003 at 05:59:41PM -0400, Chris Snyder wrote:
>  
>
>>if ( isset($foo) ) {
>>   if ( is_string($foo) && $foo=='' ) do stuff here
>>   }
>>    
>>
>
>The is_string() test is unnecessary.  You can just do $foo === ''.
>
>Back to the earlier stage of this discussion, if you're not concerned
>about the 0, null or false, you can do this whole thing in one step with
>an empty() test.
>
>Again, your style is confusing.  Your bracket is under the second if, even
>though it's closing the first if.  Let alone, I (and most style guides)
>dislike single line if statements.
>
>I just learned something interesting while confirming stuff:
>
>    $bar = 0;
>    if ($bar == '') {
>        echo '<br />bar equals empty';
>    }
>
>This comparison will evaluate to true, so the message will be printed.
>
>Weird,
>
>--Dan
>
>  
>
I had to run a quick test myself (not that I doubted anyone :)

quote " When one argument to a comparison operator is a number, the 
other argument is cast to a number."

so,

$foo = '';
$bar = (int) $foo;
echo $bar;  // displays zero

John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20030827/f44d5847/attachment.html>


More information about the talk mailing list