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 Initial Version

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

Description

In changeset 18995 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 (1)

SergeyBiryukov2 years ago

Note: See TracTickets for help on using tickets.