A variable captured by value is updated inside the closure

tx0/php:captured-variable-modifiedrecommendedwarningreliability/logicdepth fastbug

What it finds

A variable captured by value is updated inside the closure

Example from the rule's tests
<?phpfunction total($rows){    $sum = 0;    $names = [];    array_walk($rows, function ($row) use ($sum, $names) {        $sum += $row['n'];tx0 reports: $sum is captured by value, so this update is lost        $names[] = $row['name'];tx0 reports: $names is captured by value, so this update is lost    });    $count = 0;    array_walk($rows, function ($row) use (&$count) {        $count++;    });    $f = function ($x) use ($sum) {        $sum += $x;        return $sum;    };    return [$sum, $names, $count, $f];}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/php:captured-variable-modified" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/php:captured-variable-modified] reason="..."

tx0 explain tx0/php:captured-variable-modified shows the same in the terminal. Found a false positive? Report it.