note 103060 deleted from function.isset by danbrown
| From: | danbrown@php.net | Date: | Wed, 23 Mar 2011 15:15:25 +0000 |
| Subject: | note 103060 deleted from function.isset by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-178131@lists.php.net to get a copy of this message | ||
Note Submitter: Cuong Huy To
----
1) Note that isset($var) doesn't distinguish the two cases when $var is undefined, or is null.
Evidence is in the following code.
<?php
unset($undefined);
$null = null;
if (true === isset($undefined)){echo 'isset($undefined) === true'} else {echo
'isset($undefined) === false');
if (true === isset($null)){echo 'isset($null) === true'} else {echo 'isset($null) ===
false');
?>
2) If you want to distinguish undefined variable with a defined variable with a null value, then use
array_key_exist
<?php
unset($undefined);
$null = null;
if (true !== array_key_exists('undefined', get_defined_vars())) {echo '$undefined
doesnot exist';} else {echo '$undefined exists';}
if (true === array_key_exists('null', get_defined_vars())) {echo '$null exist';}
else {echo '$null doesnot exist';}
?>