Cannot Use Non-Constant Argument With Continue or Break

As of PHP 5.4.0, it is no longer possible to use a non-constant argument with continue or break. For example, an arithmetic operation in this context will result in a fatal error:

while (true) {
    break 0 + 1;
}

See execution result.

Other discontinued argument types:

As of PHP 7.0.0, it is also no longer possible to use a constant:

while (true) {
    break E_ERROR;
}

Solution

Since you need to know the argument at runtime, you need to analyze the logic of your code and use the appropriate positive integer.

Errors or Warnings

See Also