Re: [RFC] Match expression
| From: | Theodore Brown | Date: | Sun, 10 Sep 2017 16:05:06 +0000 |
| Subject: | Re: [RFC] Match expression | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-100503@lists.php.net to get a copy of this message | ||
On Saturday, September 9, 2017 6:21 AM, ilija.tovilo@me.com wrote:
> I find myself writing switch statements in PHP quite rarely. This has a few reasons:
> 1. It doesn’t have a "strict_types” version
> ...
> I assume that some people will not be so happy about having to switch-like constructs. IMO the
> implicit type conversion is the biggest issue here. Maybe we could offer a solution for this one at
> least.
I also rarely use switch, primarily because of the lack of strict comparison.
Personally I would prefer having an option for strict comparison when using switch, similar to how
in_array has an optional $strict parameter.
Would it be possible to add an optional $strict parameter to switch? E.g.
```
switch ($i, true) {
case 1:
echo 'i is 1';
break;
case: 1.0:
echo 'i is 1.0';
break;
case '1':
echo 'i is "1"';
break;
case true:
echo 'i is true';
break;
}
```
-Theodore Brown