Re: distinguish between null variable and unset variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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


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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux