Re: PHP 7.1 - Address PHPSadness #28?
| From: | Ryan Pallas | Date: | Sun, 20 Sep 2015 00:43:06 +0000 |
| Subject: | Re: PHP 7.1 - Address PHPSadness #28? | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-88383@lists.php.net to get a copy of this message | ||
On Sat, Sep 19, 2015 at 5:29 PM, Lester Caine <lester@lsces.co.uk> wrote:
> On 19/09/15 22:56, Rowan Collins wrote:
> >>> If what you want to do is avoid the notice, then you don't need to
> >>> "find out before calling is_null", you need to call isset *instead
> >>> of* is_null. Again, ignore the name, and concentrate on what it
> >>> actually does.
> >> BUT ISSET RETURNS FALSE FOR A VARIABLE THAT IS SET BUT NULL ... END OF
> >> STORY ...
> >
> > AND SO DOES IS_NULL
> >
> > The notices emitted by is_null are COMPLETELY IRRELEVANT.
>
> ? is_null returns true if the variable exists and is NULL and throws a
> notice if the variable is not set WHY is that fact COMPLETELY
> IRRELEVANT? Just because you don't think people should be coding in the
> way that it causes problems with existing code does not make it
> irrelevant we have to put up with the notices because there is no CLEAN
> way to establish that a variable exists only that it is set.
>
I would also point out that is_null returns true (after the engine produces
a notice) for undefined variables:
$ php -r "var_dump(is_null($a));"
Notice: Undefined variable: a in Command line code on line 1
Call Stack:
0.0001 118888 1. {main{() Command line code:0
*bool(true)*
So is_null does not help to determine if a plain variable is in fact null.