Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#2321 closed defect (bug) (fixed)

Array union in generate_rewrite_rules doesn't achieve expected effect.

Reported by: majelbstoat Owned by: ryan
Priority: normal Milestone:
Component: General Version: 2.0
Severity: normal Keywords: rewrite rules array union bg|has-patch
Cc:

Description

Line 1287 of classes.php:

$post_rewrite = $rewrite + $post_rewrite;

doesn't actually assign what you would expect ($rewrite followed by $post_rewrite) to $post_rewrite. It in fact assigns ($post_rewrite followed by $rewrite). The difference is subtle, but can be important for plugins that wish to generate their own rewrite rules.

An example of the problem with assignments this way is at:

http://jamietalbot.com/wp-hacks/miscellaneous/arrayuniontest.php

From this example, you can see that assigning the result to a new variable achieves the intended order. The patch supplied assigns the result temporarily to a new variable and then immediate copies it back to $post_rewrite, which fixes the problem for me on PHP versions 4.3.4 and 4.3.11.

Attachments (2)

array union assignment fix.diff (479 bytes) - added by majelbstoat 7 years ago.
Patch to ensure that the rewrite arrays are correctly unioned
array_merge to replace array union.diff (2.8 KB) - added by majelbstoat 7 years ago.
Alternative patch that replaces unions with array_merge

Download all attachments as: .zip

Change History (8)

Patch to ensure that the rewrite arrays are correctly unioned

comment:1   ryan7 years ago

We should probably change all of those unions to use array_merge instead.

I thought about that, but it does involve the overhead of a function call, when it is only a simple prepend...

Alternative patch that replaces unions with array_merge

In any case, here is a patch that converts all the array union operators in classes.php to an array_merge call. There were 6 or 7 in total, making it a more comprehensive patch than the previous one. Assuming the overhead of a function call is negligible this would be a better solution. In any case, you can decide which one to use. Tested and working on PHP 4.3.4 and 4.3.11 on latest SVN.

comment:4   ryan7 years ago

  • Owner changed from anonymous to ryan

comment:5   ryan7 years ago

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

(In [3472]) Use array_append() instead of unions. Props majelbstoat. fixes #2321

  • Milestone 2.0.1 deleted

Milestone 2.0.1 deleted

Note: See TracTickets for help on using tickets.