Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#22125 closed defect (bug) (fixed)

Prevent stomping $wp_the_query by accident

Reported by: scribu Owned by: ryan
Milestone: 3.5 Priority: high
Severity: blocker Version: 3.5
Component: Query Keywords: has-patch
Focuses: Cc:


We have this in wp-settings.php:

$wp_query =& $wp_the_query;

This was necessary in PHP4, but in PHP5 it makes it easy to overwrite $wp_the_query by accident:

// tra la la, some template file

$wp_query = new WP_Query( ... );

and in general it obscures the fact that $wp_the_query should remain frozen.

Attachments (2)

22125.diff (941 bytes) - added by scribu 8 years ago.
wp-query-test.php (601 bytes) - added by wpmuguru 8 years ago.

Download all attachments as: .zip

Change History (8)

8 years ago

#1 @scribu
8 years ago

  • Keywords has-patch added

#2 @wpmuguru
8 years ago

  • Milestone changed from Awaiting Review to 3.5
  • Severity changed from normal to critical

Attached is a page template for 2012 that demonstrates that wp_reset_query does not reset to the original query when the global $wp_query is assigned a new WP_Query. This problem is fixed by 22125.diff.

The bug was introduced in [21792]. Prior to that change query_posts returned a reference which replaced the existing $wp_query reference. After the change query_posts is returning an object which replaces the referenced object.

#3 @wpmuguru
8 years ago

  • Type changed from enhancement to defect (bug)

#4 @nacin
8 years ago

  • Priority changed from normal to high
  • Severity changed from critical to blocker

#5 @SergeyBiryukov
8 years ago

  • Version set to trunk

#6 @ryan
8 years ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In 22434:

Don't assign wp_the_query to wp_query by reference. Removing the ref avoids accidentally stomping wp_the_query.

Props scribu, wpmuguru
fixes #22125

Note: See TracTickets for help on using tickets.