Re: Strict switch statements
| From: | Stanislav Malyshev | Date: | Thu, 14 Jun 2018 22:10:37 +0000 |
| Subject: | Re: Strict switch statements | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-102267@lists.php.net to get a copy of this message | ||
Hi!
> switch ($a) {
> case FOO:
> // Works exactly as current behavior.
> break;
> case == FOO:
> // Nearly identical, though not using the ZEND_CASE optimization.
> // Can probably make this equivalent to
case FOO, but it
> felt
> like an interesting direction.
> break;
> case === FOO:
> // Only triggers if $a === FOO, no type juggling
> break;
> }
With current tendency to move to more strict interpretation and a bit
away from type juggling, I think it has its place. But I am not a big
fan to putting === there, it looks weird. Maybe go a bit further and
make the whole switch strict?
strict switch ($a) {
case FOO:
case BAR:
// both are strict ===
}
I imagine people that like strict style would want to use strict
everywhere, so for them using === every time might be annoying. This way
it makes for easier read for both strict and weak typers.
--
Stas Malyshev
smalyshev@gmail.com