note 119993 added to function.isset
| From: | p_ignorethis_lbowers at gmail dot com | Date: | Thu, 06 Oct 2016 07:26:51 +0000 |
| Subject: | note 119993 added to function.isset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206782@lists.php.net to get a copy of this message | ||
I, too, was dismayed to find that isset($foo) returns false if ($foo == null). Here's an
(awkward) way around it.
unset($foo);
if (compact('foo') != array()) {
do_your_thing();
}
Of course, that is very non-intuitive, long, hard-to-understand, and kludgy. Better to design your
code so you don't depend on the difference between an unset variable and a variable with the
value null. But "better" only because PHP has made this weird development choice.
In my thinking this was a mistake in the development of PHP. The name ("isset") should
describe the function and not have the desciption be "is set AND is not null". If it was
done properly a programmer could very easily do (isset($var) || is_null($var)) if they wanted to
check for this!
A variable set to null is a different state than a variable not set - there should be some easy way
to differentiate. Just my (pointless) $0.02.
----
Server IP: 72.52.91.14
Probable Submitter: 77.242.22.143
----
Manual Page -- http://php.net/manual/en/function.isset.php
Edit -- https://master.php.net/note/edit/119993
Del: integrated -- https://master.php.net/note/delete/119993/integrated
Del: useless -- https://master.php.net/note/delete/119993/useless
Del: bad code -- https://master.php.net/note/delete/119993/bad+code
Del: spam -- https://master.php.net/note/delete/119993/spam
Del: non-english -- https://master.php.net/note/delete/119993/non-english
Del: in docs -- https://master.php.net/note/delete/119993/in+docs
Del: other reasons-- https://master.php.net/note/delete/119993
Reject -- https://master.php.net/note/reject/119993
Search -- https://master.php.net/manage/user-notes.php