Hi, On 17 September 2015 at 19:01, Rowan Collins <rowan.coll...@gmail.com> wrote:
> On 17 September 2015 02:17:59 BST, Robert Williams <rewilli...@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