Re: [VOTE] match expression
| From: | Levi Morrison via internals | Date: | Wed, 29 Apr 2020 00:37:36 +0000 |
| Subject: | Re: [VOTE] match expression | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-109899@lists.php.net to get a copy of this message | ||
> One issue that was discussed a few weeks ago, and led to the current syntax, was too many
> variations within the switch syntax; of course, trying to do it all in one syntax is perpetuating
> that problem. However, I think Rowan has suggested a syntax that may be sufficiently
> self-documenting. To wit, independent of rustmatch (above):
>
> switch ($foo) {
> case 1: {
> Many statements here.
> }
> case 2: {
> Many statements here.
> }
> }
>
> The curly braces are already understood by most PHPers to mean "a block of
> statements", and so it's a logical jump in this case. As Rowan suggests, the {} imply a
> break. To keep it simple we should probably not allow mixing and matching in a single switch.
> Either list-style (break required) or {}-style (break implied).
>
> That handles break;
Sadly, it doesn't. That code is valid today:
<?php
$foo = 1;
switch ($foo) {
case 1: {
echo "1\n";
}
case 2: {
echo "2\n";
}
}
?>
Which outputs:
1
2