[wp-hackers] apply_filters, merge_filters and reset()
Travis Snoozy
ai2097 at users.sourceforge.net
Wed Nov 7 22:56:37 GMT 2007
Hey folks,
If I could direct some eyes to the (2.3.1) apply_filters function in
wp-includes/plugin.php, the code doesn't look right. There's a do/while
construct on (next($wp_filters[$tag]) !== false). The $wp_filters[$tag]
array is *not* explicitly reset within the function, although resetting
that array is done as a side effect of merge_filters. In all the other
functions in this file using the same (next(...)) construct,
merge_filters is called unconditionally. In apply_filters,
merge_filters is called only if the $merged_filters global is unset.
This *seems* like it's a bug (normally, array counters are reset before
attempting to iterate; calling apply_filters twice with the same
tag would seem to do nothing on the second call), but I'm unsure if the
code is like this for a specific reason.
I'm hesitant to file a bug directly on this issue, because I'm patching
that function to use a foreach instead*. The foreach will change the
semantics, because the array will always be iterated over its full
length. I want to make sure I'm not changing the *intended* semantics,
though.
--
Travis
In Series maintainer
Random coder & quality guy
<http://remstate.com/>
* For the interested, my perf #s show ~50% improvement within that
function using foreach vs. next(), and ~3-4% improvement on overall
script time. It also happens to be much more readable. ;)
More information about the wp-hackers
mailing list