Re: [Proposal] Modification to ?: functionality

From: Date: Tue, 26 Nov 2013 15:15:42 +0000
Subject: Re: [Proposal] Modification to ?: functionality
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-70404@lists.php.net to get a copy of this message
On Tue, Nov 26, 2013 at 3:43 PM, Chris London <me@chrislondon.co> wrote: > I believe these two statements are functionally equivalent: > > $foo = $foo ? $foo : 'default'; > > $foo = $foo ?: 'default'; > They are. I would like to change it so it also checks for isset() so I propose the > following would be functionally equivalent: > > $foo = isset($foo) && $foo ? $foo : 'default'; > > $foo = $foo ?: 'default'; > The would break the assumption that a reference to an uninitialized value would generate a notice, unless explicitly handled in the logic. While I also would like to have something similar to ?: to handle default values for array keys, etc., this would change a fundamental assumption that as been in place for many years now. I'm not sure if that's a BC break that would be acceptable this late. An alternative operator may be more suitable. The change proposed has also been discussed several times since the implementation of ?:. See the ifsetor-RFC: https://wiki.php.net/rfc/ifsetor It also contains links to the discussion around the feature back then. --mats

« previous php.internals (#70404) next »