[wp-hackers] apply_filters, merge_filters and reset()
Travis Snoozy
ai2097 at users.sourceforge.net
Thu Nov 8 09:31:03 GMT 2007
On Wed, 07 Nov 2007 23:23:54 -0600, Jacob <wordpress at santosj.name>
wrote:
> You should very well, make the bug report then for 2.3.2. It would at
> least fix some issues with actions that may have been edge cases.
Sigh. I guess I'll do that. ;)
<snip>
> I think the problem is that foreach doesn't expect for the array to
> be updated inside of its loop. It only does the reset before it
> starts.
each()/next() does not solve this problem by itself, and there are no
separate reset()s in the code, so foreach is the same as the current
code in this respect.
> The second issue would be that foreach acts upon a copy of
> the original array. Appending values to the original array will not
> update the array referenced in the foreach construct.
That's the killer, but only if the new item is, as you say, appended
(and that's an assumption I'm willing to make, even though I haven't
read all the code). However, then there's an issue in that calling
add_filter or add_action will void the merge, so theoretically the
set-check and (conditional) call to merge_filters needs to be done on
*every iteration* -- which would cause the array pointer to be reset in
the middle, and would in turn lead to infinite loopage.
That said, voiding the merge value doesn't make sense if you just tack
a new function onto the target -- it only makes sense to do a void if
the hooks vs. the 'all' tag is updated, at which point you need to need
to void the merged status on all the other tags at once. I don't think
the code works if you add a new "all" hook in the middle (one, because
merge_tags isn't checked/called every loop, two, because the merged
status isn't removed on the individual tags). In fact, I don't think
it will work if you call do_action("foo"), add_hook("all"),
do_action("foo").
This whole section of code is really unpleasant. :(
--
Travis
In Series maintainer
Random coder & quality guy
<http://remstate.com/>
More information about the wp-hackers
mailing list