[wp-trac] [WordPress Trac] #10535: _wp_filter_build_unique_id issues with the first time a filter is hooked by a class

WordPress Trac wp-trac at lists.automattic.com
Mon Aug 9 19:18:23 UTC 2010


#10535: _wp_filter_build_unique_id issues with the first time a filter is hooked by
a class
-------------------------------------+--------------------------------------
 Reporter:  simonwheatley            |        Owner:          
     Type:  defect (bug)             |       Status:  reopened
 Priority:  normal                   |    Milestone:  3.0.2   
Component:  Plugins                  |      Version:  2.9     
 Severity:  normal                   |   Resolution:          
 Keywords:  has-patch tested commit  |  
-------------------------------------+--------------------------------------

Comment(by jacobsantos):

 Replying to [comment:13 Denis-de-Bernardy]:
 > If I may chime in on a slightly orthogonal, albeit related issue, this
 won't work either:
 >
 > {{{
 > function foo() {
 > remove_action('bar', 'foo');
 > }
 >
 > function foo2() {
 > echo 'test';
 > }
 >
 > add_action('bar', 'foo', 10);
 > add_action('bar', 'foo2', 11);
 > do_action('bar'); // no output
 > }}}
 >
 > Or at least it didn't last I checked (writing from an iPad... Can't
 test.).

 This doesn't work because of the behavior of iteration through an array
 and pointer handling. That said, this should have been fixed when
 apply_filter() was patched to allow for removing filters. Of course a copy
 of the filter could be used that might prevent the bug.

 Regardless, the full details are a bit vague, since it has been two years
 since this problem first reared its head.

 Lets say you have 4 elements:

 {{{ element1 -> element2 -> element3 -> element4 }}}

 You iterate through element2, which removes element2, so you expect it to
 jump to element3.

 {{{ element1 -> element2 -x> element3 -> element4 }}}

 becomes:

 {{{ element1 -> element3 -> element4 }}}

 However, the reference from element2 to element3 is broken and PHP is now
 all like, "WTF? I don't see the other elements, so I guess I'm done." If
 you were to reset the array and start from the beginning, element2 would
 be gone and element1 would jump to element3 like it should.

 That is what I can gather from tests with the behavior and pinpointing it
 down 2 years ago. Whether or not it is a PHP problem is not known, but it
 is something to look out for.

 Working with a copy will not have this problem, but then you have a
 problem of wanting to remove the reference to a filter further down in the
 chain and not being able to. The solution is a bit more complex, but is
 workable with a bit of refactoring and keeping track of the current index
 and then working from there. It would also slow down the filter system.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/10535#comment:15>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list