#45480 closed defect (bug) (duplicate)
Passing array items by reference at call time isn't compatible with `call_user_func_array()`
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Plugins | Keywords: | |
Focuses: | Cc: |
Description
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.
Change History (3)
Note: See
TracTickets for help on using
tickets.
Duplicate of #45374.