Re: Inline switch as alternative to nested inline conditional
| From: | Michał Brzuchalski | Date: | Wed, 16 Oct 2019 03:33:16 +0000 |
| Subject: | Re: Inline switch as alternative to nested inline conditional | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-107553@lists.php.net to get a copy of this message | ||
Hi David,
I'm interested in this feature this is called switch expression and is on
my list of RFC to process after Object Initializer RFC.
I have an RFC in draft for that and planning to finish it soon together
with some syntax optimisations - you can see it at
https://wiki.php.net/rfc/switch-expression-and-statement-improvement
Cheers,
Michał Brzuchalski
śr., 16 paź 2019, 03:46 użytkownik David Rodrigues <david.proweb@gmail.com>
napisał:
> 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
>