Re: PHP 7.1 - Address PHPSadness #28?
| From: | Rowan Collins | Date: | Fri, 18 Sep 2015 15:35:11 +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-88334@lists.php.net to get a copy of this message | ||
Lester Caine wrote on 18/09/2015 16:17:
You don't do much real database coding do you ... NULL is returned for fields that have no entry on a secondary table, so the result set NATURALLY returns NULL.Why do you keep going on about null? We're talking about non-existent variables, not null!
We have been living with the fact that PHP barf's when trying to check for NULL for a long time.OK, now you've lost me. I can check for NULLs just fine, using is_null() if I know the variable exists (which I pretty much always do) or isset() if it might not. No barfing necessary.
There are a number of ways those variables can be generated and switching off the notices is currently the only way.The only way to do what? If you have a variable which is either null or non-existent, and you don't care which, use isset(). That's literally the same as turning off notices and then using is_null().
exists() has a place in SOME coding styles which does not require to find the 'NULL' some other way to avoid the potential notice!exists() would not be a way of avoiding the notice. exists() would be a way of distinguishing an extra state, quite separate from null. If what you want to write is "if ( ! exists($foo) || is_null($foo) ) { ... }" then that is exactly what "if ( isset($foo) )" will give you, without any notices whatsoever. Regards, -- Rowan Collins [IMSoP]