Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#56188 new defect (bug)

Attempt to read property "post_type" on null after PHP 8.1

Reported by: brmartinez's profile brmartinez Owned by:
Milestone: Awaiting Review Priority: normal
Severity: critical Version:
Component: Posts, Post Types Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

Hello, I've noticed this error in WordPress since I've installed PHP 8.1. Can you fix it?

[09-Jul-2022 16:16:45 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:16:45 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:16:45 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:16:45 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:16:45 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:16:45 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:16:45 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:16:45 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:16:45 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:16:45 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:17:00 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:17:00 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:17:00 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:17:00 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:17:00 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:17:00 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:17:00 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:17:00 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:17:00 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:17:00 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:18:11 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:18:11 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:18:11 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:18:11 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:18:11 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:18:11 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:18:11 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:18:11 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:18:11 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338
[09-Jul-2022 16:18:11 UTC] PHP Warning: Attempt to read property "post_type" on null in /home/showmetechcom/public_html/wp-includes/class-wp-query.php on line 4338

Change History (5)

This ticket was mentioned in PR #3142 on WordPress/wordpress-develop by Tabrisrp.


2 years ago
#1

  • Keywords has-patch added; needs-patch removed

get_queried_object() can return null, but there was no check for its value before trying to read the post_type property from the value.

Trac ticket: https://core.trac.wordpress.org/ticket/56188

jrfnl commented on PR #3142:


2 years ago
#2

Please add a test covering this change.

#3 @tabrisrp
2 years ago

  • Keywords has-unit-tests added

#4 @dd32
2 years ago

#56714 was marked as a duplicate.

#5 @dd32
2 years ago

This is also being tracked via #29660

Note: See TracTickets for help on using tickets.