Re: [Proposal] Modification to ?: functionality

From: Date: Tue, 26 Nov 2013 16:49:45 +0000
Subject: Re: [Proposal] Modification to ?: functionality
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-70409@lists.php.net to get a copy of this message
On 26 November 2013 15:32, Jannik Zschiesche <hello@apfelbox.net> wrote: > Hi, > > > Am Dienstag, 26. November 2013 um 16:15 schrieb Mats Lindh: > > > On Tue, Nov 26, 2013 at 3:43 PM, Chris London <me@chrislondon.co(mailto: > me@chrislondon.co)> wrote: > > > 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. > > Since the discussion about it is quite vivid at the moment: > wouldn’t this be a nice candidate for one of the changes in the next major > version? > > What are your (everyone's) thoughts on the following, given the current topic of discussion? $foo = $fo ?: 'default'; // see what I did there? I'm not sure changing the ?: to always use isset() is necessarily a good thing given my propensity for tiping mystakes. > > -- > Cheers Jannik > > >

« previous php.internals (#70409) next »