Opened 8 weeks ago
Last modified 8 weeks ago
#63998 new defect (bug)
Undefined variable warnings in WP Class
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | lowest |
| Severity: | trivial | Version: | |
| Component: | Query | Keywords: | has-patch |
| Focuses: | Cc: |
Description
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
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.
Change History (1)
This ticket was mentioned in PR #9936 on WordPress/wordpress-develop by @dd32.
8 weeks ago
#1
- Keywords has-patch added
Trac ticket: https://core.trac.wordpress.org/ticket/63998#ticket