wrote in message news:3b05768a-95b7-42de-8bb8-3d9ce0cce3a5@Spark...
it makes it impossible to group several conditions with a single break
In Swift you can group multiple conditions with a comma `,` and in Rust
with a pipe `|`. Here’s how that could look in PHP:
```php
match ($x) {
1, 2: ‘One or two’;
}
```
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.
The only thing you cannot do is this:
```php
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 `$x` being `1`. This is acceptable IMO because
this looks like a bug even if it’s intended.
For people who RTFM and know how PHP works that code is perfectly acceptable
and not buggy in the least.
then 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.
So why are you proposing a third alternative to the switch of if/elseif
statements?
--
Tony Marston
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php