Re: Re: [RFC] Match expression

From: 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...
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:
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:
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

« previous php.internals (#100500) next »