On Wed, Jan 17, 2018 at 7:28 PM, Lito <i...@eordes.com> wrote:

> No $foo ?: 'default' , it's only equivalent to (isset($foo) && $foo) ?
> $foo : 'default' if $foo exists.
>
> Also PHP has added ?? as null-coalescing operator that works with
> undefined variables/attributes/keys, my proposal is an improvement over
> this one.
>
> I don't want to endorse usage of undefined variables, can be used in a
> large set of situations, like object attributes, array keys, etc...
>

What is the use case for the ??: operator?

Null-coalesce is very common, because undefined/null are typically used to
signal default values. Using *any* falsy value to indicate a default value
seems a lot more unusual and precarious to me, especially if you consider
PHP's specific semantics around falsiness (with the string "0" being falsy).

Nikita


> On 17/01/18 19:17, Marco Pivetta wrote:
>
>> This:
>>
>> echo (isset($foo) && $foo) ? $foo : 'default';
>>
>> Is equivalent to:
>>
>> echo $foo ?: 'default';
>>
>> Please don't endorse usage of undefined variables.
>>
>

Reply via email to