> Am 16.10.2019 um 03:46 schrieb David Rodrigues <[email protected]>:
>
> Hello. I like to suggests a discussion about a FR to make possible to
> inline switch, as an alternative to nested inline conditionals.
>
> $value = switch (expr()) {
> case A1: return A2;
> case B1: return B2;
> default: return C;
> }
>
> Instead of:
>
> $expr = expr();
> $value = $expr == A1 ? A2 : ( $expr == B1 ? B2 : C );
>
> Just a discussion to check what do you think.
>
> --
> David Rodrigues
Hey David,
what's the concrete advantage of this syntax as opposed to the already possible:
$value = [
A1 => A2,
B1 => B2,
][expr()] ?? C;
there are only differences in edge cases (with floats or with type mixing) …
but for the vast majority of use cases, it is just as powerful as what you
proposed.
Bob
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php