On 17/01/18 19:43, Andrey Andreev wrote:
Hi,


On Wed, Jan 17, 2018 at 8: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...

Anyway thanks for your feedback.
Lito.

There is a shorter version:

     empty($foo) ? 'default' : $foo;

And I think that's quite convenient for the few use cases it has
(refer to Nikita's reply).

Cheers,
Andrey.

Yes, I think that:

$foo = $foo ??: 'default';

Is more clear and with less code than:

$foo = empty($foo) ? 'default' : $foo;

As ?? does.

Regards,
Lito.


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to