Bug #69476 [Nab]: is_null() must not throw warnings

From: Date: Fri, 17 Apr 2015 17:03:14 +0000
Subject: Bug #69476 [Nab]: is_null() must not throw warnings
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192160@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69476&edit=1 ID: 69476 User updated by: spam2 at rhsoft dot net Reported by: spam2 at rhsoft dot net Summary: is_null() must not throw warnings Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: Linux PHP Version: Irrelevant Block user comment: N Private report: N New Comment: > Could you please describe why you consider this to be necessary? well, why does isset() exists with your logic? - it is necessary because the isset() behavior is braindead return false in case of NULL - if i want that behavior i would just use empty() the whole purpose of isset() is to check if a variable is defined the whole purpose if is_null() is to work around broken isset() behavior and no - put a @ in front is not a clean coding style Previous Comments: ------------------------------------------------------------------------ [2015-04-17 16:57:46] spam2 at rhsoft dot net RTFM: isset($var) && !is_null($var) is nonsense because because when isset() is true it can't be NULL - just because the design mistake that isset() returns false when the value is NULL if(isset($nicht_definiert) || is_null($nicht_definiert)) is the only way to emulate a sane isset() behavior but raises a warning when the variable is undefined so you CAN NOT write code without warnings in case if you ned to know if a variable is undefined * in case of the value NULL it is not undefined * isset() has a pervert behavior returning false * if the variable is undefined is_null() raises a warning and the next time befor you close a bug or recommend something like "isset($var) && !is_null($var)" while everybody reading the docs knows that it won't work jsut read the docs ------------------------------------------------------------------------ [2015-04-17 16:52:27] nikic@php.net @cmb The question is how to detect whether a variable is defined, but null. @op You correctly surmised that there is no (obvious) way to do this. Could you please describe why you consider this to be necessary? Checking whether a *simple* variable is defined is, as far as I can tell, useless in any case. If you want to check whether an array key exists (and is null) you can use array_key_exists. Similarly for objects there is property_exists. ------------------------------------------------------------------------ [2015-04-17 16:48:53] cmb@php.net > how [...] do you test if a variable is defined with the isset() behavior > saying no if the value is NULL isset($var) && !is_null($var) ------------------------------------------------------------------------ [2015-04-17 15:49:18] spam2 at rhsoft dot net bullshit - isset() don't work when a variable is defined and contains NULL, you should read your own documentation [harry@srv-rhsoft:/mnt/data/downloads]$ php test.php [harry@srv-rhsoft:/mnt/data/downloads]$ cat test.php <?php $x = NULL; if(isset($x)) { echo "defined\n"; } ?> ------------------------------------------------------------------------ [2015-04-17 15:45:45] chx@php.net You want isset() and this has nothing to do with the specification. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=69476 -- Edit this bug report at https://bugs.php.net/bug.php?id=69476&edit=1

« previous php.bugs (#192160) next »