Re: Implicit isset in ternary operator

From: Date: Wed, 18 Jul 2012 14:20:43 +0000
Subject: Re: Implicit isset in ternary operator
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-61395@lists.php.net to get a copy of this message
Rafael, One point of clarity: On Wed, Jul 18, 2012 at 10:15 AM, Rafael Dohms <listas@rafaeldohms.com.br>wrote: > Hey Everyone, > > With the syntax improvements for 5.4 and some of the de-referencing work, > code looks so much sleeker then before, but there is still one use case > that really bugs me. > > Given this code: > > $width = (isset($config['width']))? $config['width'] : 300; > > The code is pretty straight forward, if width is set in the array, use it > otherwise use 300. > > This code would look much better if it could make use of the ternary > operator > > $width = $config['width'] ?: 300; > > The only reason for this to not work is: it throws a notice if the array > key is not there (which is the case we are covering anyway) > > This is basically because the ternary operator does not do a internal > implicit isset, only an empty. > It does not do an empty. Empty would avoid notices as well. All it does is an implicit bool cast... > Does this seem like a possible improvement we can work on? Anyone > interested in championing the change? > I like it in principle. My only concern is *why* wasn't it done this way in the first place... Is there a reason? Anthony

« previous php.internals (#61395) next »