[wp-trac] [WordPress Trac] #29660: Functions in wp_includes/query.php assume non-null return value from get_queried_object

WordPress Trac noreply at wordpress.org
Tue Sep 6 16:17:28 UTC 2022


#29660: Functions in wp_includes/query.php assume non-null return value from
get_queried_object
-------------------------------------------------+-------------------------
 Reporter:  yellyc                               |       Owner:
                                                 |  SergeyBiryukov
     Type:  defect (bug)                         |      Status:  reviewing
 Priority:  normal                               |   Milestone:  6.1
Component:  Query                                |     Version:  4.0
 Severity:  normal                               |  Resolution:
 Keywords:  2nd-opinion has-patch has-unit-      |     Focuses:
  tests php8                                     |
-------------------------------------------------+-------------------------

Comment (by noplanman):

 I agree with @bwbama that this issue has been open a tad too long.

 What I've done for now to keep the error log from growing unnecessarily,
 is to return null early when accessing the properties that cause the error
 message. This doesn't change any functionality, as `null` is returned
 anyway, it's just a matter of not outputting the error message.

 `/wp-includes/class-wp-query.php` around lines 4188 onward:
 Changing `$page_obj->ID` to `$page_obj?->ID`

 Also for other properties `$page_obj?->post_title`,
 `$page_obj?->post_name`.

 **Note** that I'm changing the file in core here, so it's needed once with
 every new WP release.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/29660#comment:57>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list