1.2.86. Bracketless Blocks¶
PHP allows one liners as for(), foreach(), while(), do/while() loops, or as then/else expressions.
It is generally considered a bad practice, as readability is lower and there are non-negligible risk of excluding from the loop the next instruction. switch() and match() cannot be without bracket.
<?php
// Legit one liner
foreach(range('a', 'z') as $letter) ++$letterCount;
// More readable version, even for a one liner.
foreach(range('a', 'z') as $letter) {
++$letterCount;
}
?>
1.2.86.1. Suggestions¶
Assign in the second branch
Assign outside the condition
1.2.86.2. Specs¶
Short name |
Structures/Bracketless |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Instant (5 mins) |
Precision |
Very high |
Available in |