Reference in foreach should be unset after loop

SonarPHP should flag code which uses a reference in a foreach loop without unsetting that reference immediately after.

Noncompliant code:

foreach ($entries as &$entry) {
    $entry += 1;
}

Compliant code:

foreach ($entries as &$entry) {
    $entry += 1;
}
unset($entry);

External references:

Type: Bug

Hello Stephen,

Thanks for the suggestion. I created SONARPHP-822 to add it to SonarPHP.

Regards