Make WordPress Core

Opened 8 months ago

Closed 8 months ago

#59146 closed defect (bug) (duplicate)

undefined array keys "host" and "scheme" in wp-includes/canonical.php

Reported by: jeremydunn's profile jeremydunn Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.3
Component: Canonical Keywords:
Focuses: Cc:


the error log for our WP site, and that of many other users, is full of errors like this:

[12-Jul-2023 00:27:45 UTC] PHP Warning: Undefined array key "scheme" in /home/dhammadhara/public_html/wp-includes/canonical.php on line 722

and this

[12-Jul-2023 00:27:45 UTC] PHP Warning: Undefined array key "host" in /home/dhammadhara/public_html/wp-includes/canonical.php on line 689

see for others complaining of the same issue.

It seems like a very basic patch would be to test for the existence of these keys (or) to add null-handling, like this:

original code:

$original_host_low = strtolower( $original['host'] );

proposed fix:

$original_host_low = strtolower( $original['host']  ?? '');

but then I'm not sure how the remainder of the code would behave.

another solution at canonical.php lines 75-78

	$original = parse_url( $requested_url );
	if ( false === $original ) {

would be to add tests for the expected array keys of $original, e.g.

if (!isset($original['host']) || !isset($original['scheme'])) {

Change History (1)

#1 @SergeyBiryukov
8 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi there, welcome to WordPress Trac!

Thanks for the report, we're already tracking this issue in #34353.

Note: See TracTickets for help on using tickets.