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

From: Date: Sun, 19 Apr 2015 13:45:39 +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-192202@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: Y Private report: N New Comment: Bob pointed out that it's possible to use get_defined_vars() in combination with array_key_exists() to check whether a variable is defined but null. Previous Comments: ------------------------------------------------------------------------ [2015-04-18 15:48:33] spam2 at rhsoft dot net > since an uninitialised variable is considered to > have the value null, a variable set to null is > considered the same as one which hasn't been > initialised. This is consistent bullshit - how can the behavior below callend consistent and how can anything you said above be true with that braindead behavior throwing a warning in once case when you pretend a unitialized variable has the value NULL [harry@srv-rhsoft:/mnt/data/downloads]$ php test.php NULL Notice: Undefined variable: y in /mnt/data/downloads/test.php on line 7 NULL [harry@srv-rhsoft:/mnt/data/downloads]$ cat test.php <?php $x = NULL; if(is_null($x)) { echo "NULL\n"; } if(is_null($y)) { echo "NULL\n"; } ?> ------------------------------------------------------------------------ [2015-04-18 15:33:54] Rowan dot Collins at gmail dot com There is a Stack Overflow question discussing this at length here: http://stackoverflow.com/q/418066/157957 If you are dynamically defining array keys or object properties, array_key_exists and property_exists allow you to check their existence regardless of value. Dynamically defining actual variables is possible, but universally worse than using an array or object container, so does not require language support. This leaves only the case where you don't know if a variable has been *initialised*; since an uninitialised variable is considered to have the value null, a variable set to null is considered the same as one which hasn't been initialised. This is consistent, well-documented, and reasonable behaviour. It may not be the behaviour you would LIKE, but insulting people on a public bug tracker is not going to convince them a change is needed. ------------------------------------------------------------------------ [2015-04-17 18:20:11] spam2 at rhsoft dot net and BTW you at your own did not understand the PHP behavior, otherwise you would not have reommended "isset($var) && !is_null($var)" while "isset() && is_null()" is just impossible and so the && construct makes no sense ------------------------------------------------------------------------ [2015-04-17 18:18:02] spam2 at rhsoft dot net well, you can't seriously claim wrong behavior correct just beause millions of programmers learned to deal with the inconsistent und unexpected behavior left and right all over the programming language ------------------------------------------------------------------------ [2015-04-17 18:15:15] cmb@php.net Harald, please reconsider your attitude. Claiming that the behavior of isset is braindead, while it obviously works well for millions of programmers, and even ranting and cursing, is certainly unrewarding. :) If you really consider it necessary to change the behavior or, more realistically, introduce a new language construct, feel free to propose a respective RFC; see the instructions in the Wiki on how to do so[1]. [1] <https://wiki.php.net/rfc/howto> ------------------------------------------------------------------------ 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 (#192202) next »