On Mon, Jul 23, 2012 at 6:12 AM, Alex Aulbach <alex.aulb...@gmail.com>wrote:
> Do we really need that as operator? Why not using new functions for > special cases. > Don't see much difference between > > $a = $b ?: $c; > > and (for example I used "i" for "if") > > $a = _i($b, $c); > > Just a manner of getting accustomed to it. > > A little bit more thinking: This could be implemented directly into > any program/project, so it is a manner of how to use PHP and not of > why it isn't added to the language. > > PS: Would it be possible to implement functions like ":?()" or "!?()" > ? Currently this is not allowed by syntax. > > > 2012/7/18 Rafael Dohms <lis...@rafaeldohms.com.br>: > > $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. > > > > Does this seem like a possible improvement we can work on? Anyone > > interested in championing the change? > > -- > Alex Aulbach > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > I do think that such operator will be great. I think that you can compare the situation to the short if syntax ($a > $b ? $c : $d) - you could use a function too that'll do the same thing, but the syntax is very useful, readable and great.