The boolean result of an in-place sort is used as if it were the sorted array
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.
<?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} 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: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.