#2321 closed defect (bug) (fixed)
Array union in generate_rewrite_rules doesn't achieve expected effect.
Reported by: | majelbstoat | Owned by: | ryan |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.0 |
Component: | General | Keywords: | rewrite rules array union bg|has-patch |
Focuses: | 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)
Change History (8)
#2
@
19 years ago
I thought about that, but it does involve the overhead of a function call, when it is only a simple prepend...
#3
@
19 years ago
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.
Patch to ensure that the rewrite arrays are correctly unioned