[wp-trac] [WordPress Trac] #63998: Undefined variable warnings in WP Class

WordPress Trac noreply at wordpress.org
Thu Sep 18 00:38:35 UTC 2025


#63998: Undefined variable warnings in WP Class
--------------------------+-----------------------------
 Reporter:  dd32          |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  lowest        |  Milestone:  Awaiting Review
Component:  Query         |    Version:
 Severity:  trivial       |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 It's possible to hit these two PHP Warnings in the `WP` class:

 > E_WARNING: Undefined variable $query in wp-includes/class-wp.php:270
 > E_WARNING: Undefined variable $matches in wp-includes/class-wp.php:273

 https://github.com/WordPress/wordpress-
 develop/blob/9b21204565430c1b22f29b5e57043adf8a71cfa5/src/wp-includes
 /class-wp.php#L268-L284

 If you trace that around a bit, you'll think `how on earth can this be
 triggered`. Well, I'll tell you - Calling this late in a request (Such as
 within a rest-api endpoint)
 {{{
         // Ugly, but this works..
         $_SERVER['REQUEST_URI'] = $url;
         wp( $_REQUEST );
 }}}

 In short: The WP::parse_request() method expects it'll be called exactly
 once, and doesn't pre-initialize the class properties / etc in the method.

 The attached PR will pre-initialize them, but adding an additional
 `isset()` would be possible too, as would `Closed: wontfix,
 _doing_it_wrong( 'dd32 is doing unsupported things.' );` I'm mostly filing
 this for future searching of these specific warnings.

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


More information about the wp-trac mailing list