Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#55222 closed defect (bug) (fixed)

PHP Warning when using 'do_parse_request' filter with '__return_false'

Reported by: dd32's profile dd32 Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.0 Priority: normal
Severity: minor Version:
Component: Query Keywords: has-patch
Focuses: Cc:

Description

When disabling request parsing via the do_parse_request filter, if you're simply disabling the parsing entirely instead of replacing, you end up with a PHP Warning:

E_WARNING: array_keys() expects parameter 1 to be array, null given in wp-includes/class-wp.php:548

This can be reproduced by this:

add_filter( 'do_parse_request', '__return_false' );

Upon looking at the WP class, it appears that the query_vars property isn't initialised to an array() until after the above filter is called, but is then expected to be set to an array in the following function calls.

It seems safe to me to simply pre-set this to an empty array, and the other class properties while we're at it.

Example workaround: https://meta.trac.wordpress.org/changeset/11592

See PR.

Change History (6)

This ticket was mentioned in PR #2341 on WordPress/wordpress-develop by dd32.


3 years ago
#1

  • Keywords has-patch added

#2 @SergeyBiryukov
3 years ago

  • Milestone changed from Awaiting Review to 6.0

SergeyBiryukov commented on PR #2341:


3 years ago
#3

Thanks for the PR! Looks like the tests did not pass previously because the isset( $this->matched_rule ) condition in WP::parse_request() needed an update to ! empty( $this->matched_rule ), since it's always set now. With this change, the tests are passing, so this seems ready for commit.

#4 @SergeyBiryukov
3 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 52804:

Query: Preinitialize the WP class properties to their default values.

This avoids an array_keys() expects parameter 1 to be array, null given PHP warning for the query_vars property in WP::build_query_string() when disabling request parsing via the do_parse_request filter.

Props dd32, SergeyBiryukov.
Fixes #55222.

#6 @SergeyBiryukov
3 years ago

In 52805:

Query: Correct the "matched rule" condition in WP::parse_request().

The WP::$matched_rule property is always set now, so we should check that it's not empty instead.

Follow-up to [52804].

See #55222.

Note: See TracTickets for help on using tickets.