Re: [RFC] Implicit isset() in Shorthand Ternary Operator
| From: | Gwynne Raskind | Date: | Thu, 18 Sep 2014 09:26:49 +0000 |
| Subject: | Re: [RFC] Implicit isset() in Shorthand Ternary Operator | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-77305@lists.php.net to get a copy of this message | ||
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