The boolean result of an in-place sort is used as if it were the sorted array

tx0/php:sort-result-useddefaultwarningreliability/collectionsdepth fastbug

What it finds

$sorted = sort($items);: the sorting functions sort the array they are given in place and return true, so their result is not the sorted array. Assigning, returning or iterating it uses a boolean where an array was meant.

From the rule's source, sort_result_used.rs.

Example from the rule's tests
<?phpfunction ordered($items){    $sorted = sort($items);tx0 reports: the result of sort is assigned, but it is a boolean    foreach (ksort($items) as $item) {tx0 reports: the result of ksort is iterated, but it is a boolean        echo $item;    }    usort($items, fn($a, $b) => $a <=> $b);    return asort($items);tx0 reports: the result of asort is returned, but it is a boolean}
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:sort-result-used" = "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:sort-result-used] reason="..."

tx0 explain tx0/php:sort-result-used shows the same in the terminal. Found a false positive? Report it.