Re: [RFC] Implicit isset() in Shorthand Ternary Operator

From: Date: Thu, 18 Sep 2014 11:32:54 +0000
Subject: Re: [RFC] Implicit isset() in Shorthand Ternary Operator
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-77306@lists.php.net to get a copy of this message
I'm seeing '??' as analogous to the way JS developers use '||', and I use that all the time when writing JS. 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. Also, not much sure about a '??=', perhaps it should be a followup RFC should '??' be accepted. On 18 September 2014 10:26, Gwynne Raskind <gwynne@darkrainfall.org> wrote: > On Sep 17, 2014, at 11:40, Matthew Fonda <mfonda@php.net> wrote: > > Hi Andrea, > > > > This is great -- thanks to you and Nikita for the work here. > > > > Syntax wise, I would prefer a function-like syntax, e.g. coalesce($a, $b, > > 'c') or ifsetor() instead of $a ?? $b ?? 'c'. I find this more > > readable, > > and it avoids any possible confusion about precedence within the > > expressions. Either way, still +1 for this feature. > > > > Best regards, > > --Matthew > > I’m STRONGLY +1 in favor of this operator, ASAP; I’ve had to write more > than a few hacks to keep a large codebase I’m responsible from being a > complete mess of isset() checks - 5.6 has saved me a lot of what used to be > ugly workarounds (variadic functions anyone?), but this one still haunts me. > > I would argue for both coalesce() (as a language token) and ?? and ??=, as > shorthand forms, giving the user a choice as to which they find more > readable. ?? is standard in both .NET and Apple’s Swift language - Apple > added it to Swift (including the chaining behavior) early during the beta > cycle due to user demand for exactly this kind of logic, and it’s been part > of C# for a long time. > > -- Gwynne Raskind > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Pete Boere Web Developer

« previous php.internals (#77306) next »