WordPress.org

Make WordPress Core

#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:

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 19 months ago.
wp-query-test.php (601 bytes) - added by wpmuguru 18 months ago.

Download all attachments as: .zip

Change History (8)

scribu19 months ago

comment:1 scribu19 months ago

  • Keywords has-patch added

comment:2 wpmuguru18 months 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.

wpmuguru18 months ago

comment:3 wpmuguru18 months ago

  • Type changed from enhancement to defect (bug)

comment:4 nacin18 months ago

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

comment:5 SergeyBiryukov18 months ago

  • Version set to trunk

comment:6 ryan18 months 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.