Re: [RFC] [DISCUSSION] Improve null-coalescing operator (??) adding empty check (??:)

From: Date: Wed, 17 Jan 2018 18:43:04 +0000
Subject: Re: [RFC] [DISCUSSION] Improve null-coalescing operator (??) adding empty check (??:)
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-101611@lists.php.net to get a copy of this message
Hi, On Wed, Jan 17, 2018 at 8:28 PM, Lito <info@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.

« previous php.internals (#101611) next »