Re: Re: [RFC] Match expression
| From: | Tony Marston | Date: | Sun, 10 Sep 2017 11:09:20 +0000 |
| Subject: | Re: Re: [RFC] Match expression | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-100500@lists.php.net to get a copy of this message | ||
wrote in message news:3b05768a-95b7-42de-8bb8-3d9ce0cce3a5@Spark...
Just because other languages have different ways of implementing certain features is no reason why PHP should include the same implementations. That ius why there are so many different languages - because they do things differently. If they were all the same there would be no need for different languages.it makes it impossible to group several conditions with a single breakIn Swift you can group multiple conditions with a comma,and in Rust with a pipe|. Here’s how that could look in PHP:match ($x) { 1, 2: ‘One or two’; }
The only thing you cannot do is this:For people who RTFM and know how PHP works that code is perfectly acceptable and not buggy in the least.switch ($x) { case 1: echo “One\n”; case 2: echo “Two\n”; break; }Meaning you cannot “bleed through” the first case into the second, executing both in case of$xbeing1. This is acceptable IMO because this looks like a bug even if it’s intended.
So why are you proposing a third alternative to the switch of if/elseif statements? -- Tony Marstonthen why can't you use if/elseif instead of making the language more complicated?Because that’s usually the perfect use case for a switch statement.