Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#45480 closed defect (bug) (duplicate)

Passing array items by reference at call time isn't compatible with `call_user_func_array()`

Reported by: henrywright's profile henry.wright 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)

#1 @johnbillion
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #45374.

#2 @henry.wright
6 years ago

For the record call_me should be baz above

#3 @SergeyBiryukov
6 years ago

  • Component changed from General to Plugins
Note: See TracTickets for help on using tickets.