[nycphp-talk] ${$variable}

Chris Snyder csnyder at
Wed Aug 27 14:56:23 EDT 2003

Michael Southwell wrote:

> A line of code says this:
>   if (!(${$foo})) do something if the value is empty
> If $foo="bar" and $bar="something" then will ${$foo} evaluate to 
> "something"--which I assume is the purpose of the curly brackets?  

Most definitely.

> But it doesn't seem to work when the value is empty, though I would 
> swear it used to.  or maybe there is something with an empty value 
> evaluating true anyway, so I need to use =="" or ==="", or =='' or 
> ==='' (single quotation marks)?  

You could use =="" -- if ( ${$foo}=="" ) do something -- which is 
testing for an empty string instead of boolean false, which is what your 
sample is doing. If $bar=0 then the code you have would work.


More information about the talk mailing list