Re: [RFC] Implicit isset() in Shorthand Ternary Operator

From: Date: Wed, 10 Sep 2014 09:31:44 +0000
Subject: Re: [RFC] Implicit isset() in Shorthand Ternary Operator
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-77135@lists.php.net to get a copy of this message
On Tue, Sep 9, 2014 at 12:58 AM, Adam Harvey <aharvey@php.net> wrote: > On 8 September 2014 07:56, Christoph Becker <cmbecker69@gmx.de> wrote: >> Am 08.09.2014 15:58, schrieb Andrea Faulds: >>> We could add such an operator, perhaps with the ?? syntax. However, I >>> don’t really like the idea. It’s too similar to ?: so I don’t think >>> it’d be accepted, and even if it was, I’m not sure we really need >>> another operator. I’d much rather just make ?: do what, IMO, is the >>> right thing and what it always should have done. >> >> I'd rather had a shortcut for the following: >> >> isset($_GET['foo']) ? $_GET['foo'] : BAR > > Agreed. That's what ifsetor requests have generally boiled down to > over the years, so it seems to be what the masses want. > > It's what _I_ want, anyway. :) > >> Of course, it is not possible to change the ?: operator to work this way >> for BC reasons, but a new operator such as ?? might make sense. > > +1 on ?? — there's precedent for it, and it means we don't have to > explain why the shorthand form of an operator behaves differently to > the long form, which is just going to confuse users. After a 2nd look I have to agree here too. Changing behavior in something so widely used as the current operator will likely create more pains. A new operator, clearly documented, sounds much cleaner, even more as it does something different anyway. -- Pierre @pierrejoye | http://www.libgd.org

« previous php.internals (#77135) next »