Re: Adding explicit intent for SWITCH/CASE fall through?
| From: | A.L.E.C | Date: | Sun, 20 Oct 2019 07:01:22 +0000 |
| Subject: | Re: Adding explicit intent for SWITCH/CASE fall through? | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-107584@lists.php.net to get a copy of this message | ||
On 10/20/19 2:39 AM, Mike Schinkel wrote:
>> case X:
>> if (something) {
>> fallthrough;
>> }
>> something-else;
>> break;
>> case Y: ....
>
> Interesting.
>
> What would you expect this to do? It is not intuitively obvious to me.
Directly jump to the next
case (as goto would do).
Also, fallthrough probably shouldn't be just a no-op, it should be jump. Consider this code
case X:
fallthrough;
break;
case Y:
It should be clear what would happen in such cases.
>> Then, don't we need a way to jump outside of the whole switch statement? Ah,
>> there's goto already. So, maybe extend
>> goto somehow?
>
> Is that not what break is for?
Right. I was too much on throwing new ideas that I missed that some are already
implemented ;). The point was that fallthrough with these added functionality mentioned
above would be very close to goto. On the other hand:
case X:
goto next; // or goto case; ?
case Y:
sounds worse than:
case X:
fallthrough;
case Y:
or
case X:
pass;
case Y:
> The fact a potential feature is a no-op does not discredit it for me; instead I focus on the
> benefits the proposed feature can provide.
>
> In this case the benefits would be to alerting developer when they accidentally omit
> instructions to PHP of their intentions. And that seems to me to be something (almost?) everyone
> would want to see embraced? Clearly* PHPStan and many Linux developers would like the same[1][2].
Maybe if it was a feature (keyword) that could be useful in other places not only in
switch...
I proposed "pass" because it might have some uses out of switch (nothing comes to my mind,
though right now) and because "fallthrough" is kinda hard word for non-native speakers.
"pass" exists in Python. https://docs.python.org/2.0/ref/pass.html
>> It might be not useful enough to justify a BC break.
That was my intention, to find more value in a new feature to justify BC break.
--
Aleksander 'A.L.E.C' Machniak
Kolab Groupware Developer [http://kolab.org]
Roundcube Webmail Developer [http://roundcube.net]
----------------------------------------------------
PGP: 19359DC1 # Blog: https://kolabian.wordpress.com