Using a `break` in a loop without curly braces causes `ForbiddenBreakContinueOutsideLoop`
afilina opened this issue · comments
Anna Filina commented
Bug Description
Using a break
in a loop without curly braces causes incorrect ForbiddenBreakContinueOutsideLoop
error.
Given the following reproduction Scenario
The issue happens when running this command:
phpcs -ps file.php --standard=PHPCompatibility --runtime-set testVersion 8.1
... over a file containing this code:
for($i=0;$i<=5;$i++)
if($i==3)
{
var_dump($i);
break;
}
This code is perfectly valid in PHP 8.1: https://3v4l.org/iOKAJ#v8.1.18
I'd expect the following behaviour
No errors or warnings.
Instead this happened
PHPCompatibility.ControlStructures.ForbiddenBreakContinueOutsideLoop.FatalError
Environment
Environment | Answer |
---|---|
PHP version | 8.2.3 |
PHP_CodeSniffer version | 3.5.3 |
PHPCompatibility version | (not sure how to check inside PHPCO, lastest as of 2023-04-11) |
Install type | PHPCO |
Tested Against develop
branch?
- I have verified the issue still exists in the
develop
branch of PHPCompatibility.
Juliette commented
Anna Filina commented
Thanks. I'll fix the code prior to running the PHPCompatibility standard.