[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
Sun Aug 2 13:04:51 UTC 2009


#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:  new
 Priority:  normal         |   Milestone:  2.9
Component:  Plugins        |     Version:  2.9
 Severity:  normal         |    Keywords:     
---------------------------+------------------------------------------------
Changes (by dd32):

  * version:  => 2.9
  * milestone:  Unassigned => 2.9


Comment:

 > attachment 10535.diff added
  * Main change is lines 685-7, the rest are just WordPress Coding Standard
 cleanups.

 Testing code:
 {{{
 include 'wp-load.php';

 class Foo {     function test() { echo 'TEST'; } }
 class Baz extends Foo { }

 $a = new Foo();
 $b = new Foo();
 $c = new Baz();

 var_dump( _wp_filter_build_unique_id('test', array(&$a, 'test'), 10) );
 var_dump( _wp_filter_build_unique_id('test', array(&$b, 'test'), 10) );
 var_dump( _wp_filter_build_unique_id('test', array(&$c, 'test'), 10) );

 var_dump( _wp_filter_build_unique_id('test', array(&$a, 'test'), 10) );
 var_dump( _wp_filter_build_unique_id('test', array(&$b, 'test'), 10) );
 var_dump( _wp_filter_build_unique_id('test', array(&$c, 'test'), 10) );

 do_action('test');
 }}}

 Output before:
 {{{
 string 'Footest0' (length=8)
 string 'Footest0' (length=8)
 string 'Baztest0' (length=8)
 string 'Footest3' (length=8)
 string 'Footest4' (length=8)
 string 'Baztest5' (length=8)
 }}}
 Notice that the FIRST calling will return 0, not 3, 4 or 5?

 Testing it again:
 {{{
 var_dump( _wp_filter_build_unique_id('test', array(&$a, 'test'), 10) );
 var_dump( _wp_filter_build_unique_id('test', array(&$a, 'test'), 10) );
 var_dump( _wp_filter_build_unique_id('test', array(&$a, 'test'), 10) );
 }}}

 output:
 {{{
 string 'Footest0' (length=8)
 string 'Footest3' (length=8)
 string 'Footest3' (length=8)
 }}}

 So its just the first calling which is failing.

 After my patch, Here's the output of the first test case:
 {{{
 string 'Footest3' (length=8)
 string 'Footest4' (length=8)
 string 'Baztest5' (length=8)
 string 'Footest3' (length=8)
 string 'Footest4' (length=8)
 string 'Baztest5' (length=8)
 }}}
 Which is now correct, $a = 3, $b = 4, $c = 5 each time, Whereas before,
 All would be 0 first call, and 3/4/5 2nd and every call after..

 Lets test filter/action adding/removing.
 {{{
 add_action( 'test', array(&$a, 'test') );
 remove_action( 'test', array(&$a, 'test') );

 do_action('test');
 }}}

 Before:
 {{{
 TEST
 }}}
 Seems the filter hasnt been removed (As expected, since its ID differs)

 After patch:
 {{{
 NULL OUTPUT
 }}}
 No output, Therefor, Action was removed.

 Sorry for the long post, But thats the method i've used to test, 99% sure
 this has no negitive side effects, It works with multiple instances of
 objects, as  well as different objects, Functions and Static calling isnt
 touched.

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


More information about the wp-trac mailing list