Re: PHP 7.1 - Address PHPSadness #28?

From: Date: Thu, 17 Sep 2015 12:41:52 +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-88281@lists.php.net to get a copy of this message
Hi, On 17 September 2015 at 19:01, Rowan Collins <rowan.collins@gmail.com> wrote: > On 17 September 2015 02:17:59 BST, Robert Williams <rewilliams@thesba.com> > wrote: > > An unset variable is not null. Rather, it’s > >completely undefined, and PHP yells at you for just that reason if you > >try to access it. Then, it turns around and tries to appease you by > >giving you null. > > > I see it as rather the other way around: it happily gives you a null, but > then says "oh, by the way, you never actually initialised that variable to > null". Not an error, just a friendly aside. > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > Here is an example where exists would be useful; // input is {name:'Ted', birth_dt: null} $input = json_decode(file_get_contents('php://input')); // I should have used property_exists() instead of isset().. wasn't expecting a null.. if ( isset($input->birth_dt) && ! isValidBirthDate($input->birth_dt) ) { throw new Exception('Bad birth date'); } saveToDb($input); // Oh no... I clobbered birth date ​Terry​

« previous php.internals (#88281) next »