Re: [RFC] Implicit isset() in Shorthand Ternary Operator
| From: | Kingsquare.nl - Robin Speekenbrink | Date: | Tue, 16 Sep 2014 20:46:21 +0000 |
| Subject: | Re: [RFC] Implicit isset() in Shorthand Ternary Operator | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-77276@lists.php.net to get a copy of this message | ||
2014-09-16 22:00 GMT+02:00 Christoph Becker <cmbecker69@gmx.de>:
> Andrea Faulds wrote:
>
>> On 16 Sep 2014, at 19:38, Adam Harvey <aharvey@php.net> wrote:
>>
>>> On 16 September 2014 11:34, Andrea Faulds <ajf@ajf.me> wrote:
>>>> By popular demand, I’ve changed the RFC to instead propose a ?? operator, after
>>>> Nikita Popov generously donated a working ?? patch. In doing so, the RFC is renamed “Null Coalesce
>>>> Operator”.
>>>>
>>>> Please read it:
>>>> https://wiki.php.net/rfc/isset_ternary
>>>
>>> Love it! Kudos to you and Nikita.
>
> +1
>
>>> Is it possible to chain ?? operators; ie $value = $foo ?? $bar ?? 'default’?
>>
>> Yep:
>>
>> $ sapi/cli/php -r '$x = NULL; $y = NULL; $z = 3; var_dump($x ?? $y ?? $z);'
>> int(3)
>>
>> $ sapi/cli/php -r '$x = ["yarr" => "meaningful_value"];
>> var_dump($x["aharr"] ?? $x["waharr"] ?? $x["yarr"]);'
>> string(16) "meaningful_value"
>
Hi,
As a userland point of view on this: will this have a shorthand? i.e.
what will happen if i leave out the second part?
ie.
$var = $_GET['test'] ?? ;
would that be the same as
$var = @$_GET['test'];
The RFC isnt clear in this regard (or that the righthand side of the
operator _is_ required... maybe it's me ?
Regards
Robin Speekenbrink