[wp-trac] [WordPress Trac] #59146: undefined array keys "host" and "scheme" in wp-includes/canonical.php
WordPress Trac
noreply at wordpress.org
Fri Aug 18 23:56:16 UTC 2023
#59146: undefined array keys "host" and "scheme" in wp-includes/canonical.php
--------------------------+-----------------------------
Reporter: jeremydunn | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Canonical | Version: 6.3
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
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 https://wordpress.org/support/topic/php-warning-undefined-array-keys-
in-wp-includes-canonical-php/ 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 ) {
return;
}
}}}
would be to add tests for the expected array keys of {{{$original}}}, e.g.
{{{
if (!isset($original['host']) || !isset($original['scheme'])) {
return;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59146>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list