On 18 Sep 2014, at 12:32, Pete Boere <p...@the-echoplex.net> wrote:

> I'm seeing '??' as analogous to the way JS developers use '||', and I use
> that all the time when writing JS.

PHP already has a direct equivalent to ||, namely the ?: operator. However, 
unfortunately PHP always spits out a notice on non-existent indices, unlike JS 
which just results in undefined, so we need to add a special operator to 
silence it.

> Personally I wouldn't be interested in a function version because the
> short-circuiting of '??' is an important distinction; not something you can
> replicate with a function. Therefore having both would be confusing IMO.

We could use a function *syntax*, though, but I don’t like this idea. 
coalesce() and ifsetor() are both ugly to me, and it’s not super obvious what 
they do:

    var_dump(coalesce($_GET[‘foobar’], 3));

vs.

    var_dump($_GET[‘foobar’] ?? 3);

?? also has the advantage of being shorter.

> Also, not much sure about a '??=', perhaps it should be a followup RFC
> should '??' be accepted.

It’d make sense to do it within this RFC if possible. If it seems too 
controversial, it could always have a separate vote within the RFC.
--
Andrea Faulds
http://ajf.me/





--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to