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

[email protected] (Rowan Collins)
Newsgroups php.internals
Message-ID <[email protected]>
On 09/09/2014 18:08, [email protected] 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]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.