#57358 closed enhancement (fixed)
PHP 8 deprecation in wp-includes/category-template.php uasort() helper
Reported by: | Webrocker | Owned by: | audrasjb |
---|---|---|---|
Milestone: | 6.2 | Priority: | normal |
Severity: | normal | Version: | 6.1.1 |
Component: | Taxonomy | Keywords: | php8 has-patch commit |
Focuses: | Cc: |
Description
category-template.php, line 1089 ff:
function _wp_object_count_sort_cb( $a, $b ) {
return ( $a->count > $b->count );
}
This throws a Deprecation warning with PHP 8: "Deprecated: uasort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in wp-includes/category-template.php
changing the above code to
function _wp_object_count_sort_cb( $a, $b ) {
return ( $a->count - $b->count );
}
fixes the warning for me, while still sorting as before.
Attachments (1)
Change History (21)
#1
@
21 months ago
- Component changed from General to Taxonomy
- Keywords needs-patch php8 added
- Milestone changed from Awaiting Review to 6.2
#3
@
21 months ago
- Keywords needs-patch added; has-patch removed
@jigar-bhanushali Thanks for working on this. Unfortunately, your patch cannot be accepted as you are using PHP 7.0+ syntax, while WordPress still supports PHP 5.6.
This ticket was mentioned in PR #3804 on WordPress/wordpress-develop by iamwebrocker.
21 months ago
#4
- Keywords has-patch added; needs-patch removed
Change return value from boolean to int less, equal or greater than zero as requited by php 8. Using substraction instead of the spaceship operator (<=>) for php 5.6 compat
Trac ticket: https://core.trac.wordpress.org/ticket/57358
@mukesh27 commented on PR #3804:
21 months ago
#5
@iamwebrocker Can you please update the PR title to Fix PHP 8 deprecation warning in category-template.php
?
iamwebrocker commented on PR #3804:
21 months ago
#7
@mukeshpanchal27 thanks for the catch :)
This ticket was mentioned in Slack in #core by costdev. View the logs.
20 months ago
This ticket was mentioned in Slack in #core by costdev. View the logs.
20 months ago
@audrasjb commented on PR #3804:
20 months ago
#10
Added a quick commit to address a tiny typo in the docblock ;)
#11
@
20 months ago
- Keywords commit added; changes-requested removed
This ticket was discussed during the bug scrub. Feedback on the PR has been addressed and this is ready for commit
consideration. Adding the appropriate keyword.
Additional props: @audrasjb
20 months ago
#12
Just wondering if there are tests for this function and if not, if now would be a good time to add those ?
@audrasjb commented on PR #3804:
20 months ago
#13
I'd suggest to secure this bugfix for 6.2 and to open a new ticket for complete test coverage, since test fixes can be committed anytime during the beta cycle. What do you think @costdev ?
20 months ago
#14
@audrasjb Yes that sounds good to me!
@jrfnl Do you have any thoughts on datasets, beyond sorting 4, 3, 2, 1 ->1, 2, 3, 4
and 3, 1, 4, 2 -> 1, 2, 3, 4
?
#15
@
20 months ago
- Owner set to audrasjb
- Resolution set to fixed
- Status changed from new to closed
In 55214:
@audrasjb commented on PR #3804:
20 months ago
#16
Committed in https://core.trac.wordpress.org/changeset/55214
20 months ago
#17
@jrfnl Do you have any thoughts on datasets, beyond sorting
4, 3, 2, 1 -> 1, 2, 3, 4
and3, 1, 4, 2 -> 1, 2, 3, 4
?
Well, what about 2, 1, 2, 1
? Or -2, -1, -3 ,-2
?
Also: the function contains a lot of assumptions....
- The function doesn't have any type declarations, but does include a presumption that an object will be passed, though it doesn't specify which type of object _(IIRC I know why, and that's why an interface should be added)_...
- ... and that the passed object will have a
count
property. - ... and that this
count
property is publicly accessible. - ... and that this
count
property will actually be set. - ... and that the data type stored in the
count
property will always be numeric or at least a scalar (juggleable to int).
Want me to go on ? I can think of plenty of other ways to break this function.... 😈
@costdev Does this give you enough inspiration ?
Hi there, welcome to WordPress Trac! Thanks for the ticket, moving to 6.2 for review.