An array is searched with loose comparison

tx0/php:loose-searchstrictwarningmaintainability/designdepth fastsmell

What it finds

in_array($value, $list): without true as the third argument, the search compares loosely, so in_array('abc', [0]) was true before PHP 8 and in_array(null, [0]) still is. array_search and array_keys with a search value behave alike.

From the rule's source, loose_search.rs.

Example from the rule's tests
<?phpfunction has($value, $list){    $a = in_array($value, $list);tx0 reports: in_array compares loosely    $b = in_array($value, $list, true);    $c = array_search($value, $list);tx0 reports: array_search compares loosely    return [$a, $b, $c];}
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 from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

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

tx0 explain tx0/php:loose-search shows the same in the terminal. Found a false positive? Report it.