On Wed, Jan 21, 2009 at 05:27:35PM -0800, Jack Bates wrote:

> How can I tell the difference between a variable whose value is null and
> a variable which is not set?
> 
> // cannot use === null:
> 
> ket% php -r '$null = null; var_dump(null === $null);'
> bool(true)
> ket% php -r 'var_dump(null === $unset);'
> bool(true)
> ket%
> 
> // - cannot use isset() either:
> 
> ket% php -r '$null = null; var_dump(isset($null));'
> bool(false)
> ket% php -r 'var_dump(isset($unset));'
> bool(false)
> ket%

Oh I *love* this problem. I still haven't found the perfect solution for
it. But since a lot of things in PHP float around as strings, I often
use strlen(trim($var)) == 0 to determine the "emptiness" of a variable.
But it all depends on what type of variable you expect to receive. I
don't have this problem so much with methods and functions, since I
specifically engineer them to give me exact results. But I get it when
testing POST and GET variables from web pages.

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to