NYCPHP Meetup

[nycphp-talk] ${$variable}

Phil Powell soazine at erols.com
Wed Aug 27 15:35:04 EDT 2003


Wait, I'm confused.  If a variable is set to 0, then it is also false as
well, am I right??

$foo = 'bar';
$bar = 0;

then !${$foo} would be true only if $bar is set to what can be considered
false, which can be 0.  If $bar were not set or set to something other than
0 then the statement itself would throw an error because it is not a boolean
check.

Hmm.. conundrum.. I defer this to higher brains than mine..

Phil


----- Original Message ----- 
From: "Brian Pang" <bpang at bpang.com>
To: <shiflett at php.net>; "NYPHP Talk" <talk at lists.nyphp.org>
Sent: Wednesday, August 27, 2003 3:31 PM
Subject: Re: [nycphp-talk] ${$variable}


> 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
> >
> >
>
>
>
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk




More information about the talk mailing list