Re: [RFC] Match expression
| From: | Niklas Keller | Date: | Sun, 10 Sep 2017 16:27:56 +0000 |
| Subject: | Re: [RFC] Match expression | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-100504@lists.php.net to get a copy of this message | ||
2017-09-10 18:05 GMT+02:00 Theodore Brown <theodorejb@outlook.com>:
> 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 ;ü
> s×�›…“Y…V÷‡$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;
> }
I'd very much prefer a "strict switch ($i) { ... }" over a second parameter..
Regards, Niklas