[nycphp-talk] ${$variable}

Analysis & Solutions danielc at
Wed Aug 27 17:23:43 EDT 2003


On Wed, Aug 27, 2003 at 04:40:30PM -0400, Chris Snyder wrote:
> To test for an empty string, you have to test that it is both empty AND 
> a string.
> if ( is_string($$foo) && empty($$foo) ) do empty string stuff here

Do that the other way around.  Always do an empty() check first, just in
case the variable isn't set at all.  This prevents PHP from generating an
"undefined variable" Notice error.

Do be aware that...

   $bar = 0;    // is_string() will be false, empty() will be true
   $bar = '0';  // is_string() will be true,  empty() will be true

$var == '' can be the appropriate test in some circumstances.


     FREE scripts that make web and database programming easier
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7th Ave #4AJ, Brooklyn NY    v: 718-854-0335   f: 718-854-0409

More information about the talk mailing list