[wp-trac] [WordPress Trac] #16661: Review use of apply_filters_ref_array() and do_action_ref_array()

WordPress Trac wp-trac at lists.automattic.com
Wed Mar 9 11:08:40 UTC 2011


#16661: Review use of apply_filters_ref_array() and do_action_ref_array()
--------------------------------------+-----------------------------
 Reporter:  scribu                    |       Owner:
     Type:  enhancement               |      Status:  new
 Priority:  normal                    |   Milestone:  Future Release
Component:  General                   |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch 3.2-early php5  |
--------------------------------------+-----------------------------

Comment (by hakre):

 Replying to [comment:10 scribu]:
 > Nevermind, I forgot to pass by reference. Point taken.

 It was not obvious for me on first sight either, it's always better to
 look together over this stuff.

 Thanks for creating some test-script, I've extended it into a suite of
 multiple tests and could run it against different PHP versions (as mu-
 plugin here). I've stripped the warnings for a better read. That's on an
 unpatched trunk and it's interesting to see that it differs between PHP
 5.2 and 5.3:

 {{{
 PHP Version: 5.2.14 (allow_call_time_pass_reference: 0)

  #01: callback_std(), native invokation, standard parameter
 = "original"
  #02: callback_std(), native invokation, call-time reference parameter
 = "modified"
  #03: callback_std(), do_action(), standard parameter
 = "original"
  #04: callback_std(), do_action(), call-time reference parameter
 = "original"
  #05: callback_std(), do_action_ref_array(), standard parameter
 = "original"
  #06: callback_std(), do_action_ref_array(), call-time reference parameter
 = "modified"
  #07: callback_ref(), native invokation, standard parameter
 = "modified"
  #08: callback_ref(), native invokation, call-time reference parameter
 = "modified"
  #09: callback_ref(), do_action(), standard parameter
 = "original"
  #10: callback_ref(), do_action(), call-time reference parameter
 = "original"
  #11: callback_ref(), do_action_ref_array(), standard parameter
 = "original"
  #12: callback_ref(), do_action_ref_array(), call-time reference parameter
 = "modified"


 PHP Version: 5.3.5 (allow_call_time_pass_reference: 0)

  #01: callback_std(), native invokation, standard parameter
 = "original"
  #02: callback_std(), native invokation, call-time reference parameter
 = "modified"
  #03: callback_std(), do_action(), standard parameter
 = "original"
  #04: callback_std(), do_action(), call-time reference parameter
 = "original"
  #05: callback_std(), do_action_ref_array(), standard parameter
 = "original"
  #06: callback_std(), do_action_ref_array(), call-time reference parameter
 = "modified"
  #07: callback_ref(), native invokation, standard parameter
 = "modified"
  #08: callback_ref(), native invokation, call-time reference parameter
 = "modified"
  #09: callback_ref(), do_action(), standard parameter
 = "original" -- !! hook function not invoked. !!
  #10: callback_ref(), do_action(), call-time reference parameter
 = "original" -- !! hook function not invoked. !!
  #11: callback_ref(), do_action_ref_array(), standard parameter
 = "original" -- !! hook function not invoked. !!
  #12: callback_ref(), do_action_ref_array(), call-time reference parameter
 = "modified"
 }}}

 The interesting part is that [http://php.net/manual/en/function.call-user-
 func-array.php call_user_func_array()] will issue a warning in PHP 5.3.5
 if the hook callback expects the parameter to be passed by reference and
 it isn't. That will prevent the callback from being invoked even. So this
 influences callbacks with parameters by reference invoked by do_action()
 and do_action_ref_array().

 Those callbacks are getting invoked in PHP 5.2.14.

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


More information about the wp-trac mailing list