RE: [PHP-DEV] [RFC] Deprecate and remove continue targeting switch
| From: | Zeev Suraski | Date: | Wed, 27 Jun 2018 06:00:36 +0000 |
| Subject: | RE: [PHP-DEV] [RFC] Deprecate and remove continue targeting switch | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-102478@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Nikita Popov [mailto:nikita.ppv@gmail.com]
> Sent: Tuesday, June 26, 2018 9:28 PM
> To: Stanislav Malyshev <smalyshev@gmail.com>
> Cc: PHP internals <internals@lists.php.net>
> Subject: Re: [PHP-DEV] [RFC] Deprecate and remove continue targeting switch
>
> This RFC resolves the following issue:
>
> a) In PHP "switch" is considered a looping structure, for this reason
> "break" and
> "continue" both apply to "switch", as aliases. For PHP, these are
> reasonable
> semantics, as PHP supports multi-level breaks. It would be very questionable if
> "break N" and "continue N" could refer to different loop structures just
> because
> there is a "switch" involved somewhere.
>
> b) On the other hand, other languages, such as C and C-based languages, use a
> different behavior, where "continue" refers to the enclosing loop. As these
> languages don't have multi-level breaks, these semantics are also reasonable.
>
> This leaves us in a position where "continue" means different things in PHP and
> in other syntactically similar languages, causing confusing for programmers
> familiar with them. This is solved by simply prohibiting the case that is
> ambiguous. This is not a loss for PHP developers (who use "break" instead of
> "continue" for switch statements anyway), but it is a gain for programmers from
> other languages not familiar with this detail (as they get an error pointing them
> to one of the correct alternatives).
>
> All of this is not a big issue, it's just removing a papercut. IIRC this was originally
> motivated by me seeing some bug reports about this behavior.
I think it would be helpful to gauge the levels of these bug reports to understand whether it's
worth the trouble.
Ultimately - even after this change, C developers won't be able to use the C semantics
they're used to, as (e.g. in the example in the RFC) - 'continue;' won't work as
they'd expect - and they'd have to acquaint themselves with 'continue 2;'.
It's true that if we 'force' them to acquaint themselves with multi-level loop
control structures there's reduced 'continue;' erroneously. But unless this is
really A Thing, as in, something pretty common - I think the mess involved with forcing people who
have working code to try and (a) understand the change, and (b) understand their (potentially quite
ancient) code flows may outweigh the benefits.
Zeev