Just always be sure to unset $value afterwards :)
$array = array(1,2,3,4,5);
foreach ($array as &$value) {
echo $value; // some non-mutating action
}
$value = 'woops';
print_r($array); // ([0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => woops) foreach ($array as & $ref) {
// Do something with $ref
} unset ($ref);
i.e. put the `unset()` call on the same line as the closing brace, forever "welding" it to that block.