[nycphp-talk] ${$variable}
Brian Pang
bpang at bpang.com
Wed Aug 27 15:31:43 EDT 2003
right, isn't !$$foo checking to see if whether the var is defined or
not? or if it's been explicitly set to untrue, as in $foo = false
in this case, it works out that it has been set, to 0 (zero), which is
not "empty" nor is it "false"
> I'd like to make a small note regarding this topic. I think it's much more
> readable (and correct) to use the empty() function, especially if that
is what
> you are wanting to check.
>
> Consider this:
>
> <?
> $foo = 'bar';
> $bar = 0;
>
> if (!$$foo)
> {
> echo '<p>$bar is empty</p>';
> }
> ?>
>
> That echo statement isn't exactly telling the whole truth, is it? $bar
isn't
> empty; it is the integer 0. Conditional statements are evaluated as
boolean,
> and 0 evaluates to false.
>
> Consider this as an alternative:
>
> <?
> $foo = 'bar';
> $bar = 0;
>
> if (empty($$foo))
> {
> echo '<p>$bar is empty</p>';
> }
> ?>
>
> To me, it is much easier to read, and it might be more valid, depending on
> whether you are really wanting to test whether something is empty and not
> whether it is false.
>
> Hope that helps.
>
> Chris
>
> =====
> Become a better Web developer with the HTTP Developer's Handbook
> http://httphandbook.org/
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
>
>
More information about the talk
mailing list