1.2.1354. Use Variable Created Inside Loop¶
When a variable is created inside a loop, it should also be used in the loop. Otherwise, the variable will be overwritten by each loop, and become dead code.
<?php
foreach($a as $b => $c) {
$c = 1;
}
?>
1.2.1354.1. Connex PHP features¶
1.2.1354.1.1. Suggestions¶
Remove the variable from the loop
Add usage to that variable inside the loop
Turn the variable into a property
1.2.1354.1.2. Specs¶
Short name |
Structures/UseVariableInsideLoop |
Rulesets |
|
Exakat since |
2.3.7 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |