[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 09:38:56 UTC 2021


#52199: Query string is expecting a array but is receiving a string
--------------------------+-----------------------------
 Reporter:  zeshanb       |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Permalinks    |    Version:  5.6
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Hi there,

 When trying to use the request filter in a template functions file Apache
 with PHP 8 is throwing this error:

 {{{
  PHP Fatal error:  Uncaught TypeError: array_keys(): Argument #1 ($array)
 must be of type array, null given in /home/freshinstall/public_html/wp-
 includes/class-wp.php:535
 Stack trace:
 #0 /home/freshinstall/public_html/wp-includes/class-wp.php(535):
 array_keys(NULL)
 #1 /home/freshinstall/public_html/wp-includes/class-wp.php(623):
 WP->build_query_string()
 #2 /home/freshinstall/public_html/wp-includes/class-wp.php(747):
 WP->query_posts()
 #3 /home/freshinstall/public_html/wp-includes/functions.php(1291):
 WP->main('')
 #4 /home/freshinstall/public_html/wp-blog-header.php(16): wp()
 #5 /home/freshinstall/public_html/index.php(17):
 require('/home/freshinst...')
 #6 {main}
   thrown in /home/freshinstall/public_html/wp-includes/class-wp.php on
 line 535
 }}}


 in wp-class.php following lines:

 {{{#!php
 <?php
 public function build_query_string() {
                 $this->query_string = '';
                 foreach ( (array) array_keys( $this->query_vars ) as
 $wpvar ) {
                         if ( '' != $this->query_vars[ $wpvar ] ) {
                                 $this->query_string .= ( strlen(
 $this->query_string ) < 1 ) ? '' : '&';
                                 if ( ! is_scalar( $this->query_vars[
 $wpvar ] ) ) { // Discard non-scalars.
                                         continue;
                                 }
                                 $this->query_string .= $wpvar . '=' .
 rawurlencode( $this->query_vars[ $wpvar ] );
                         }
                 }
 }}}


 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');
 }}}


 When trying to just display it as a string using a error_log function:

 {{{#!php
 <?php
 error_log("What is this query string? ". $query_string ."", 0);
 }}}


 In error log:
 {{{
 What is this query string? Array
 }}}


 Kind Regards,

 Zeshan

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


More information about the wp-trac mailing list