note 112011 deleted from function.isset by sobak

From: Date: Sat, 10 Dec 2016 09:57:04 +0000
Subject: note 112011 deleted from function.isset by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208421@lists.php.net to get a copy of this message
Note Submitter: Hayle Watson ---- <?php return isset($nonexistentarray['foo']); ?> Returns false without trouble (assuming $nonexistent array does not exist). <?php $foo = 17; return isset($nonexistentarray[$foo]); ?> Also returns false without trouble. But, oddly, <?php return isset($nonexistentarray[$nonexistentkey]); ?> While returning false, also triggers a notice regarding the undefined variable "$nonexistentkey". Some thought shows that this is the right behaviour (we're testing for the existence of an array element, but we need to know which array element we're testing the existence of), but it probably isn't obvious. This implies that: <?php $extantarray[null] = 42; return isset($extantarray[$nonexistentkey]); ?> Triggers a notice and returns true.

« previous php.notes (#208421) next »