note 106000 deleted from function.array-key-exists by crell
| From: | crell@php.net | Date: | Wed, 29 Jun 2022 20:40:30 +0000 |
| Subject: | note 106000 deleted from function.array-key-exists by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218750@lists.php.net to get a copy of this message | ||
Note Submitter: glitch dot mr at gmail dot com
----
As you might know, isset() is actually working like @$variable===NULL. As the result, it
doesn't actually catch variables set to NULL. If you want to check if variable is set (even to
NULL), you can use array_key_exists on $GLOBALS, like there.
<?php
$me = null;
$se = 1;
unset($se);
// $he is not set
if(array_key_exists('me', $GLOBALS)) echo "\$me exists\n";
if(array_key_exists('se', $GLOBALS)) echo "\$se exists\n";
if(array_key_exists('he', $GLOBALS)) echo "\$he exists\n";
?>
In this case, only $me will be detected as $se was removed when code was running and $he was never
set.