Re: [RFC] Implicit isset() in Shorthand Ternary Operator
| From: | Rowan Collins | Date: | Tue, 09 Sep 2014 18:27:01 +0000 |
| Subject: | Re: [RFC] Implicit isset() in Shorthand Ternary Operator | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-77115@lists.php.net to get a copy of this message | ||
On 09/09/2014 18:08, rparker@yamiko.org wrote:
I agree and think we should go with a different operator as others suggested. If not ?? than we could use ?= like $foo ?= “default string”.That reads like an assignment, rather than an expression - particularly given PHP's large number of evaluate-and-assign operators (+=, *=, etc). Actually, that might be a useful addition in its own right. For a full set, we could have the following: // Evaluation as boolean: $bar = (bool)$bar ? $bar : $baz; $bar = $bar ? $bar : $baz; $bar = $bar ?: $baz; $bar ?:= $baz; // Test for null / isset: $bar = isset($bar) ? $bar : $baz; $bar = $bar ?? $baz; $bar ??= $baz; Not the most readable, perhaps, but then "shorthand" and "readable" are often in conflict with one another. Regards, -- Rowan Collins [IMSoP]