A comparison or logical operator has the same operand on both sides
What it finds
$a == $a, $x && $x, $n - $n: an operator with the same operand on both sides gives a fixed result or just the operand, and the code usually meant two different things, as $a == $b. Operands that call something, assign or increment are left alone, since they can differ between the two evaluations. Arithmetic that is a common idiom, such as $x * $x and $s . $s, is not reported.
From the rule's source, identical_operands.rs.
<?phpfunction compare($a, $b, $items){ if ($a == $a) {tx0 reports: both operands of == are $a return 1; } $ok = $a['k'] && $a['k'];tx0 reports: both operands of && are $a['k'] $zero = $b - $b;tx0 reports: both operands of - are $b $square = $b * $b; $twice = $a . $a; $random = rand() == rand(); return $a === $b || count($items) > 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:identical-operands" = "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:identical-operands] reason="..."tx0 explain tx0/php:identical-operands shows the same in the terminal. Found a false positive? Report it.