[wp-trac] [WordPress Trac] #52199: Query string is expecting a array but is receiving a string
WordPress Trac
noreply at wordpress.org
Fri Jan 1 15:01:46 UTC 2021
#52199: Query string is expecting a array but is receiving a string
--------------------------+----------------------
Reporter: zeshanb | Owner: (none)
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: Permalinks | Version: 5.6
Severity: normal | Resolution: invalid
Keywords: | Focuses:
--------------------------+----------------------
Comment (by SergeyBiryukov):
Hi there, welcome to WordPress Trac! Thanks for the report.
> Following in funtions.php in theme:
>
>
> {{{#!php
> <?php
> function remove_page_from_query_string($query_string)
> {
>
> error_log("What the bleep is this query string? ".
var_export($query_string) ."", 0);
>
> //return $query_string;
> }
>
> add_filter('request', 'remove_page_from_query_string');
> }}}
Just to clarify a bit more, since you're using `add_filter()`, you have to
uncomment `return $query_string;` here, as a filter must always return a
value. Otherwise, as it stands, that code is equivalent to:
{{{
add_filter( 'request', '__return_null' );
}}}
This would cause a warning in PHP 7.4 and earlier versions:
{{{
Warning: array_keys() expects parameter 1 to be array, null given in wp-
includes/class-wp.php on line 535
}}}
and a fatal error in PHP 8.0 or later.
I think the warning or error is appropriate here, as `WP::$query_vars` is
documented as an array, and expected to be an array in multiple other
places. Returning `null` instead is a developer error and should be
treated accordingly.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/52199#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list