1.2.83. Blind Variable Used Beyond Loop

Foreach() loops defines variables, which are traditionally used only inside the loop block. Using them beyond that limit often leads to surprises.

<?php

foreach($a as $b => $c) {
     echo "$b : $c\n";
}
// $b is set inside the loop, but used beyond
$max = $b;

?>

1.2.83.1. Specs

Short name

Structures/BlindVariableUsedBeyondLoop

Rulesets

All, Suggestions

Exakat since

2.5.3

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Medium

Available in

Entreprise Edition, Exakat Cloud