#53474 closed defect (bug) (fixed)
Improve Walker compatibility with PHP8
Reported by: | sunxiyuan | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.8 | Priority: | normal |
Severity: | major | Version: | 5.8 |
Component: | General | Keywords: | has-patch php8 |
Focuses: | Cc: |
Description
PHP 8 introduced a new numeric and string comparison mechanism
For the following code:
<?php 0 == '';
True under PHP 7 and False under PHP 8.
There is the following statement in line 345 of the Walker class (wp-includes/class-wp-walker.php):
<?php if ( 0 == $e->$parent_field ) {
If $e->$parent_field is an empty string, the judgment result of the statement in PHP 7 and PHP 8 will be inconsistent.
The question broke the reply order of my bbPress forum.
The offending code should be changed to:
<?php if ( 0 == (int) $e->$parent_field ) {
Change History (7)
This ticket was mentioned in PR #1407 on WordPress/wordpress-develop by sunxiyuan.
3 years ago
#1
- Keywords has-patch added
#3
@
3 years ago
- Milestone changed from Awaiting Review to 5.8
- Owner set to SergeyBiryukov
- Status changed from new to reviewing
#4
@
3 years ago
Hi there, welcome to WordPress Trac! Thanks for the ticket and the patch.
I think we can use an empty()
check here, for consistency with the change to the ::walk()
method in [35876].
There are three similar instances of these checks in a few methods:
WP_Walker::walk()
WP_Walker::paged_walk()
WP_Walker::get_number_of_root_elements()
It looks like [35876] only fixed the first instance because the Menus screen only used the ::walk()
method, and the other two methods can currently still throw a PHP notice if a non-existing property is checked. So using empty()
in all the three places would fix that in the other two methods too, as well as the issue reported here.
I'll commit the change shortly, which also includes a unit test @aristath and I worked on.
3 years ago
#7
Closing as committed via https://core.trac.wordpress.org/changeset/51204
Trac ticket: https://core.trac.wordpress.org/ticket/53474
Trac ticket: