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

From: Date: Wed, 17 Sep 2014 13:41:57 +0000
Subject: Re: [RFC] Implicit isset() in Shorthand Ternary Operator
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  Groups: php.internals 
Request: Send a blank email to internals+get-77285@lists.php.net to get a copy of this message
2014-09-17 10:58 GMT+02:00 Sara Golemon <php@golemon.com>: > >> On Sep 16, 2014, at 13:46, "Kingsquare.nl - Robin Speekenbrink" >> <robin@kingsquare.nl> wrote: >> >> As a userland point of view on this: will this have a shorthand? i.e. >> what will happen if i leave out the second part? >> >> ie. >> $var = $_GET['test'] ?? ; >> >> would that be the same as >> $var = @$_GET['test']; >> >> The RFC isnt clear in this regard (or that the righthand side of the >> operator _is_ required... maybe it's me ? >> > The equivalent of your error suppressed example would be: > $var = $_GET['test'] ?? null; > > I don't think it gains anyone much to have another form just to save four characters (for > the default null). > > Someone mentioned an assignment version which isn't covered in niki's patch but would > be a fairly trivial addition. > > $var ??= expr; > > Which essentially means: > if (!isset($var)) { > $var = expr; > } > > I'd kinda like that for completeness, but will vote for this with or without the > assignment version. > > -Sara Sara, Indeed that's what i meant. I'm afraid that i just wasn't clear the first time. But would indeed also like to see the ??= in one go. This would make the operator a direct first-class citizen of the language instead of halfway there ;) Thanks again, i'll butt out now ;) Robin

« previous php.internals (#77285) next »