A count or length is compared with zero in a way that is always true or always false

tx0/php:impossible-length-checkdefaultwarningreliability/collectionsdepth fastbug

What it finds

count($items) < 0 and strlen($s) >= 0: a count or a length is never negative, so the comparison always has the same result, and the check meant something else, usually == 0 or > 0.

From the rule's source, impossible_length_check.rs.

Example from the rule's tests
<?phpfunction check($items, $name){    if (count($items) < 0) {tx0 reports: this comparison of count with 0 is always false        return 1;    }    if (strlen($name) >= 0) {tx0 reports: this comparison of strlen with 0 is always true        return 2;    }    if (0 > sizeof($items)) {tx0 reports: this comparison of sizeof with 0 is always false        return 3;    }    return count($items) > 0;}
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 in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/php:impossible-length-check" = "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:impossible-length-check] reason="..."

tx0 explain tx0/php:impossible-length-check shows the same in the terminal. Found a false positive? Report it.