[wp-hackers] call time pass by reference (PHP 5.4 in-compatibilities)

Andrew Nacin wp at andrewnacin.com
Fri Dec 28 22:55:13 UTC 2012

On Fri, Dec 28, 2012 at 5:24 PM, Vid Luther <vid at zippykid.com> wrote:

> But every now and then, especially in BuddyPress, we run into this issue
> where lots of calls are being made to do_action() and apply_filters()
> This means the core functions need their declarations changed.
> I'm wondering how big of an undertaking this is, since this is supported
> through PHP 5.0, changing the declaration should not have any adverse
> effects.

I'd have to see specific instances to be sure, but generally speaking,
this is the result of passing an object by reference to an action or filter.
In core, we have done this with do_action_ref_array() and
apply_filters_ref_array(), rather with do_action() or apply_filters().

In PHP 5.x, this is no longer needed for objects, and it doesn't make
much sense to need a reference for anything besides objects, anyway.
So, we are no longer using apply_filters_ref_array() and
do_action_ref_array() in core. We should probably "soft-deprecate" these
functions with a message in the Codex.

However, *we can't remove existing instances* of _ref_array() calls
without breaking plugins. Plugin callbacks tied to existing _ref_array()
actions might be explicitly asking for their value to be passed by
reference, like so:

do_action_ref_array( 'example_hook', array( &$var ) );
add_action( 'example_hook', 'my_callback' );
function my_callback( &$var ) {}

If they suddenly stop receiving the variable by reference, an E_WARNING
is issued. That's no fun.

So, I'm not entirely sure of a path forward here, and open to suggestions.



More information about the wp-hackers mailing list