Re: [RFC] Implicit isset() in Shorthand Ternary Operator
| From: | Christoph Becker | Date: | Mon, 08 Sep 2014 14:56:11 +0000 |
| Subject: | Re: [RFC] Implicit isset() in Shorthand Ternary Operator | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-77104@lists.php.net to get a copy of this message | ||
Am 08.09.2014 15:58, schrieb Andrea Faulds:
> On 8 Sep 2014, at 13:04, Shashank Kumar <shashankkumar.me@gmail.com>
> wrote:
>
>> Rather than giving a new meaning to an old operator why not have a
>> different operator for this? .NET has a 'null coalescing' operator
>> for the same purpose which works out quite well in the given
>> situation and is non-ambiguous as well.
>> http://msdn.microsoft.com/en-us/library/ms173224.aspx
>
> We could add such an operator, perhaps with the ?? syntax. However, I
> don’t really like the idea. It’s too similar to ?: so I don’t think
> it’d be accepted, and even if it was, I’m not sure we really need
> another operator. I’d much rather just make ?: do what, IMO, is the
> right thing and what it always should have done.
I'd rather had a shortcut for the following:
isset($_GET['foo']) ? $_GET['foo'] : BAR
What the "Implicit isset() in Shorthand Ternary Operator" RFC proposes
is not equivalent (despite the RFC's name), consider e.g.
$_GET['foo'] === ""
$_GET['foo'] === "0"
Of course, it is not possible to change the ?: operator to work this way
for BC reasons, but a new operator such as ?? might make sense.
--
Christoph M. Becker