Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#22125 closed defect (bug) (fixed)

Prevent stomping $wp_the_query by accident

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

Description

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 14 years ago.
wp-query-test.php​ (601 bytes ) - added by wpmuguru 14 years ago.

Download all attachments as: .zip

Change History (8)

@scribu
14 years ago

#1 @scribu
14 years ago

  • Keywords has-patch added

#2 @wpmuguru
14 years ago

  • Milestone Awaiting Review → 3.5
  • Severity normal → 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
14 years ago

  • Type enhancement → defect (bug)

#4 @nacin
14 years ago

  • Priority normal → high
  • Severity critical → blocker

#5 @SergeyBiryukov
14 years ago

  • Version → trunk

#6 @ryan
14 years ago

  • Owner set to ryan
  • Resolution → fixed
  • Status new → 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.