Fix usort callback functions to return integers #40945
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The callback function to
usort
is supposed to return anint
https://www.php.net/manual/en/function.usort.php
The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
callback([mixed](https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.mixed) $a, [mixed](https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.mixed) $b): int
Fix
usort
calls in core so that they do return anint
. Some of them were returning boolean true/false.I don't think that there is any real behavior change. Returning
true
is just like returning1
and so in reality the sorter will make the same decision in this case. Returningfalse
is just like returning0
- so the sorter will think that the items have the same sort "priority", but actually it might be the case that-1
should have been returned. So items might end up out-of-order.https://www.php.net/manual/en/function.usort.php
How Has This Been Tested?
CI
Types of changes
Checklist: