Bug #69476 [Com]: is_null() must not throw warnings
| From: | nikic@php.net | Date: | Fri, 17 Apr 2015 16:52:28 +0000 |
| Subject: | Bug #69476 [Com]: is_null() must not throw warnings | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-192158@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
Comment by: nikic@php.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:
@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.
Previous Comments:
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
[2015-04-17 15:40:49] spam2 at rhsoft dot net
Description:
------------
since isset() returns false in case a variable contains NULL (which is a major design error)
is_null() MUST not throw a warning in case of a undefined variable
Test script:
---------------
<?php
if(isset($nicht_definiert) || is_null($nicht_definiert))
{
echo "defined\n";
}
?>
Expected result:
----------------
no warning or a sane isset() behavior with sanity in mind
how the hell do you test if a variable is defined with the isset() behavior saying no if the value
is NULL
Actual result:
--------------
Notice: Undefined variable: nicht_definiert in /mnt/data/downloads/test.php on line 2
defined
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69476&edit=1