[wp-trac] [WordPress Trac] #55222: PHP Warning when using 'do_parse_request' filter with '__return_false'

WordPress Trac noreply at wordpress.org
Tue Feb 22 04:05:19 UTC 2022

#55222: PHP Warning when using 'do_parse_request' filter with '__return_false'
 Reporter:  dd32          |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:
 Severity:  minor         |   Keywords:
  Focuses:                |
 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-

 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()` [https://github.com/dd32/wordpress-
 develop/blob/trunk/src/wp-includes/class-wp.php#L144-L150 until after the
 above filter is called], but [https://github.com/dd32/wordpress-
 develop/blob/trunk/src/wp-includes/class-wp.php#L546-L548 is then expected
 to be set to an array] in the [https://github.com/dd32/wordpress-
 develop/blob/trunk/src/wp-includes/class-wp.php#L758-L760 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.

Ticket URL: <https://core.trac.wordpress.org/ticket/55222>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list