WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 8 months ago

#19412 closed defect (bug)

Changeset 18995 can lead to Notice: Undefined index: wp_the_query — at Version 3

Reported by: bobbingwide Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.3
Component: Query Keywords: has-patch close
Focuses: Cc:

Description (last modified by ryan)

In changeset r18995 there were two changes to query.php
The comment "new does not require by reference" applies to the first but not the second change.

Should the assignment by reference in wp_reset_query have been removed?

The reported problem is:
http://wordpress.org/support/topic/plugin-wordpress-seo-by-yoast-notice-undefined-index-wp_the_query?replies=2#post-2477593

I had the same problem and questioned the suggested fix.
What I don't understand is why there is no Notice: message for the original code.

Try running this code.

<?php
error_reporting( E_ALL );  
@ini_set('display_errors',1);

function bad() {
  print_r( __FUNCTION__ );
  echo "\n";

  $GLOBALS = array( 'wp_query' => 'set' );
  print_r( $GLOBALS );
  unset($GLOBALS['wp_query']);
  $GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
  print_r( $GLOBALS );
  $GLOBALS['wp_query'] =& $GLOBALS['wp_the_query'];
  print_r( $GLOBALS );
}

function good() {
  print_r( __FUNCTION__ );
  echo "\n";
  $GLOBALS = array( 'wp_query' => 'set' );
  print_r( $GLOBALS );
  unset($GLOBALS['wp_query']);
  $GLOBALS['wp_query'] =& $GLOBALS['wp_the_query'];
  print_r( $GLOBALS );
  $GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
  print_r( $GLOBALS );
}

good();
bad();

Change History (4)

SergeyBiryukov2 years ago

comment:1 SergeyBiryukov2 years ago

19412.patch adds a _doing_it_wrong() message if wp_reset_query() was called before query_posts().

comment:2 SergeyBiryukov2 years ago

  • Keywords has-patch added

comment:3 ryan2 years ago

  • Description modified (diff)
Note: See TracTickets for help on using tickets.