On 30 March 2026 19:48:05 BST, Larry Garfield <[email protected]> wrote:

> ... break is the natural keyword for that, as it already means "stop this 
> control structure and go to the end of it."
>
>continue means "stop this iteration of a control structure and go to the next 
>one."  But in this case, there is no next one.  switch makes it an alias for 
>break, for whatever reason lost to history, but given that it now throws a 
>warning that seems to now be considered a mistake, so we don't see a reason to 
>propagate that mistake.


I agree with Tim that making break and continue define targets differently is a 
really bad idea.

It's fine for a single "break;" or "continue;", but with PHP's count-based 
targeting, it would lead to cases like this:

if ( definitely_right($loop_item) ) {
    $found_item = $loop_item;
    break 4;
}
elseif ( definitely_wrong($loop_item) ) {
    // targeting the same loop, but there's a couple of "using" or "switch" 
blocks in between
    continue 2;
}


If "break 2" terminates a "using" block, there are only two sane behaviours for 
"continue 2":

- terminate that same block, as though it was a single-iteration loop
- throw an Error, because the operation is not meaningful


Looking back at the discussion of "continue targeting switch", I see I made the 
same point back then: https://externals.io/message/102393#102500

The consensus in that discussion was to *only* add a Warning, with no plan for 
further changes. It's not a deprecation, or a workaround for hard to change 
legacy behaviour; it's just a helpful hint to the developer that their code 
might have a mistake in it.


Regards,

Rowan Tommins
[IMSoP]

Reply via email to