Re: [RFC] switch expression
| From: | Ilija Tovilo | Date: | Wed, 25 Mar 2020 16:22:11 +0000 |
| Subject: | Re: [RFC] switch expression | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-109300@lists.php.net to get a copy of this message | ||
Hi Dennis
Thanks for your feedback!
> you can fall through to other cases without break
You could do the same using the || operator.
> what about the default case?
I haven't described the default case in my proposal but it is exactly what you'd expect it
to be:
```php
$var = true switch {
$x > 0 => 1,
$x < 0 => -1,
default => 0,
};
```
> What about the following if-expression-syntax:
That would work (once again, Rust already does it) though not with the return keyword. We'd
still need a block expression to pass the value from the block to the if expression. When I compare
the two I definitely think the match expression is more readable.
Regards