[wp-trac] [WordPress Trac] #41745: Uncaught Error in get_query_var when $wp_query is null (was: Uncaught Exception in get_query_var when $wp_query is null)

WordPress Trac noreply at wordpress.org
Mon Aug 28 16:32:22 UTC 2017


#41745: Uncaught Error in get_query_var when $wp_query is null
--------------------------+------------------------------
 Reporter:  kbjohnson90   |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Query         |     Version:  4.8.1
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------
Changes (by kbjohnson90):

 * keywords:  reporter-feedback =>


Comment:

 Rather, it is an `Uncaught Error`, not an exception.

 `Fatal error: Uncaught Error: Call to a member function get() on null in
 /app/public/wp-includes/query.php on line 29`
 `Error: Call to a member function get() on null in /app/public/wp-
 includes/query.php on line 29`

 The addition of a check and early return should resolve this issue.

 {{{#!php
 <?php
 function get_query_var( $var, $default = '' ) {
         global $wp_query;
         if( ! isset( $wp_query ) || ! method_exists( $wp_query, 'get' ) )
 return $default;
         return $wp_query->get( $var, $default );
 }
 }}}
 `wp-includes/query.php#26`

 Looking at submitting a patch, but still new to Trac.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/41745#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list