[wp-trac] [WordPress Trac] #45480: Passing array items by reference at call time isn't compatible with `call_user_func_array()`

WordPress Trac noreply at wordpress.org
Tue Dec 4 09:28:37 UTC 2018


#45480: Passing array items by reference at call time isn't compatible with
`call_user_func_array()`
--------------------------+-----------------------------
 Reporter:  henry.wright  |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 `call_user_func_array()` is used inside the `apply_filters()` method
 inside the `WP_Hook` class. The function doesn't pass the second argument
 as a single variable to the callback. This is an example of what happens:

 **controller.php**
 {{{
 call_user_func_array( 'call_me', array( 'foo', 'bar' ) );
 }}}

 **file.php**
 {{{
 function baz( $arg1, $arg2 ) {
     var_dump( $arg1, $arg2 );
 }
 }}}

 This will result in warnings in new versions of PHP if we try to pass
 array items by reference at call time. Here is an example taken from the
 constructor in `WP_Styles`:

 {{{
 do_action_ref_array( 'wp_default_styles', array(&$this) );
 }}}

 **wp-includes/script-loader.php**
 {{{
 function wp_default_styles( &$styles ) {
     // ...
 }
 }}}

 **Summary**

 We can't pass by reference at call time in new versions of PHP. Even
 passing array items by reference at call time will result in a warning
 because of the way `call_user_func_array()` passes items to the callback.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45480>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list