Nothing in a while loop changes the variables of its condition
What it finds
Nothing in a while loop changes the variables of its condition
<?phpfunction count_up($n){ $i = 0; while ($i < $n) {tx0 reports: the loop body never changes what its condition reads echo $i; } $j = 0; while ($j < $n) { $j++; } $k = 0; while ($k < $n) { if (stop()) { break; } } while ($more) { $more = fetch(); }} function drain(array $processes, array $queue, array $seen){ while ($processes) { foreach ($processes as $i => $process) { if ($process->done()) { unset($processes[$i]); } } } while ($queue) { handle(array_pop($queue)); } while (count($seen) < 3) { $seen[] = next_item(); } while ($seen) {tx0 reports: the loop body never changes what its condition reads echo $seen[0]; }} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/php:loop-condition-never-changes" = "off"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:loop-condition-never-changes] reason="..."tx0 explain tx0/php:loop-condition-never-changes shows the same in the terminal. Found a false positive? Report it.