A condition assigns a literal instead of comparing with it
What it finds
if ($status = 'done'): a condition that assigns a literal is always true or always false, and was almost always meant as the comparison ==. Assigning the result of a call, as while ($row = next_row()), is a common idiom and is left alone.
From the rule's source, constant_assignment_condition.rs.
<?phpfunction check($status, $db){ if ($status = 'done') {tx0 reports: the condition $status = 'done' assigns instead of comparing return true; } while ($row = $db->fetch()) { handle($row); } if ($status == 'done') { return false; } return null;} 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:constant-assignment-condition" = "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:constant-assignment-condition] reason="..."tx0 explain tx0/php:constant-assignment-condition shows the same in the terminal. Found a false positive? Report it.