Re: distinguish between null variable and unset variable

From: Date: Fri, 23 Jan 2009 10:41:47 +0000
Subject: Re: distinguish between null variable and unset variable
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-287039@lists.php.net to get a copy of this message
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% 
Although this is a good problem to lose time for I think it is pointless. Since assigning the null constant to a var is making PHP to pretend like it never existed. Is this not the point? Without this feature I can think many cases that isset or is_null would be useless. You could always assign to something the empty string '' and use empty() to check it as an alternative. BTW what are you trying to do? -- Thodoris

« previous php.general (#287039) next »