You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are instances where we use switches inside a loop, followed by cases whereby once the code inside the case is processed, we directly need to skip to the next iteration, thereby using continue. Although working fine, this generates the following warning from >=PHP 7.3ref.
PHP Warning: “continue” targeting switch is equivalent to “break”. Did you mean to use “continue 2”
Ideally, we should use break inside switch case, followed by processing left if any.
Description:
We can implement a rule that ensures only valid continue statements are used within switch cases.
Continue should not be allowed within a switch case unless it's part of a loop in which case it is a valid continue.
If a continue is found inside a switch case without a loop, it should be replaced with a break statement to avoid unintended behaviour.
Example:
switch ($var) {
case 1:
continue; // This should trigger a warning and suggest replacing with 'break' .
break;
case 2:
for ($i = 0; $i < 10; $i++) {
continue; // This is valid and should be ignored by the sniff.
}
break;
}
The text was updated successfully, but these errors were encountered:
Issue:
continue
. Although working fine, this generates the following warning from>=PHP 7.3
ref.break
inside switch case, followed by processing left if any.Description:
Example:
The text was updated successfully, but these errors were encountered: