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

From: Date: Thu, 18 Sep 2014 11:49:12 +0000
Subject: Re: [RFC] Implicit isset() in Shorthand Ternary Operator
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-77308@lists.php.net to get a copy of this message
Pete Boere wrote (on 18/09/2014):
I'm seeing '??' as analogous to the way JS developers use '||', and I use that all the time when writing JS.
Actually, JS's || is more analogous to the existing ?: operator, because it checks for truthiness, not definedness (!empty() rather than isset(), in PHP terms). PHP: echo false ?: "" ?: 0 ?: "default"; JS: console.log( false || "" || 0 || "default" ); The behaviour around undefined variables is a bit different, but that's a property of JS as a language, not any suppression by the || operator (console.log(x) with undefined x is an error; console.log(x.y) with x as an empty object is not). -- Rowan Collins [IMSoP]

« previous php.internals (#77308) next »