Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?

If you are upgrading your PHP environment from version 6.x to 7.x, specifically moving onto PHP 7.3 or later while maintaining legacy codebases like Symfony 2.8, you will inevitably encounter a specific runtime warning. The message [Symfony\Component\Debug\Exception\ContextErrorException] Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? is not merely an annoyance; it signals a fundamental change in language semantics that breaks code written under older standards.

This error occurs because PHP 7 introduced a strict distinction between continue and continue 2. In versions prior to PHP 7, using continue inside a nested loop or within a switch statement implicitly targeted the innermost enclosing loop. While this behavior was convenient for certain control flow patterns, it often led to bugs where developers intended to skip the remainder of an iteration but accidentally exited the entire loop structure.

In PHP 7 and beyond, the default continue keyword targets the current loop iteration only. If you are inside a switch statement that resides within a for, foreach, or while loop, using continue without an explicit number will execute the next iteration of that specific loop. However, if the control flow logic expects to exit the outer loop context immediately, the old behavior (implicit continue 2) was required.

Consider a typical pattern found in older Symfony components or custom legacy controllers where a developer iterates over a collection and checks conditions:

foreach ($items as $item) {
    switch ($type) {
        case 'active':
            // Process active item
            break;
        case 'inactive':
            // Skip this specific iteration
            continue; 
            // In PHP 6, this might have continued the outer loop if nested differently
            // or exited based on context.
    }
}

If your code relies on continue to jump out of an outer while loop that wraps a switch statement, or if the logic assumes continue acts as a global break for the switch's enclosing block without specifying the level, PHP 7 will throw this ContextErrorException. The engine is explicitly telling you: "You are using the implicit behavior from PHP 6 where continue meant 'go to the next outer loop,' but in modern PHP, that means nothing unless you specify it."

The fix is straightforward but requires careful inspection of your control flow logic. You must determine if the intention was to skip the current iteration (continue) or to exit the entire surrounding loop structure immediately (continue 2). If the legacy code was designed to break out of an outer loop upon a specific condition inside a switch, you must update the statement:

// PHP 7.3+ compliant fix for intended behavior
if ($conditionMet) {
    continue 2; 
}

Failing to address this results in logic errors where data processing stops prematurely or skips blocks that should be executed, leading to subtle bugs that are difficult to debug because the code runs without fatal errors but produces incorrect output.

Upgrading a Symfony 2.8 application to PHP 7.3 forces you to audit your dependency graph and core component code for these legacy constructs. While Symfony 2.8 is quite old and officially unsupported, many community projects still rely on it. If you are maintaining such a project, the trade-off involves rewriting control flow logic in critical paths to ensure compatibility with modern PHP versions without relying on deprecated implicit behaviors.

For new projects or migrations, this serves as a strong reminder to always be explicit about loop iteration levels. Always use continue 1 or simply continue for the inner scope, and continue 2 only when you explicitly need to jump over an enclosing loop level. This practice eliminates ambiguity and prevents compatibility issues with future PHP versions where such implicit behaviors will likely be removed entirely.

Our network