Re: PHP7 Coalesce operator

From: Date: Mon, 23 Nov 2015 20:08:10 +0000
Subject: Re: PHP7 Coalesce operator
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-89347@lists.php.net to get a copy of this message
On Mon, Nov 23, 2015 at 9:52 AM, shadda <shadda@gmail.com> wrote: > Er, that should read, “anything non (null, false, undefined) is true” > >> On Nov 23, 2015, at 11:51 AM, shadda <shadda@gmail.com> wrote: >> >> Hey, thanks for responding. >> >> However, I still think that misses the point, or at least the true utility of what I’m >> proposing. >> >> In practice, you can ignore E_NOTICE and php will happily treat null and !isset() as the >> same thing in *most* cases, so that’s not a good indicator of truthiness. >> >> Basically in ECMA, anything non-null, false, or undefined is true. PHP is very similar in >> that regard, but our reliance on E_NOTICE to (ahem) enforce isset() checks is why, I assume, we’re >> introducing the ?? operator to begin with. >> >> I just think it’d be nice to have a small variation on this feature that was less >> concerned with a (defined|null) semantic and more in keeping with PHP’s overall handling of >> implicit type conversion in expressions. >> >> Does that make more sense? >> >>> On Nov 22, 2015, at 12:41 PM, Andrea Faulds <ajf@ajf.me> wrote: >>> >>> Hi, >>> >>> shadda wrote: >>>> I had a question-suggestion based around the cool new operator we’re getting in >>>> PHP7, the ?? operator, which as I understand it is the functional equivalent to perl’s // >>>> operator; in that they both test for whether or not a variable is defined, rather than it’s >>>> truthiness. >>> >>> This is not strictly correct. Though something of a misnomer, the 'null coalesce >>> operator' checks if a variable doesn't exist, but also that it is not null, i.e. it >>> functions like isset(). >>> >>> Thanks. >>> >>> -- >>> Andrea Faulds >>> http://ajf.me/ >>> >>> -- >>> PHP Internals - PHP Runtime Development Mailing List >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >> > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > Ignoring E_NOTICE is generally considered bad practice by many, and turning them off just to use ternaries instead of null coalesce (a feature we already have) doesn't seem like a benefit. The ?? is used the same as "a = b || c" in Ruby or JS. Doing that in PHP wouldn't work well as || works a bit differently, so ?? is used instead, just like C and Swift. Basically... it's all good. And even if you hate it you're months too late to raise a concern. :)

« previous php.internals (#89347) next »