A variable captured by value is updated inside the closure
What it finds
A variable captured by value is updated inside the closure
<?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];} 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:
[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.