[wp-hackers] passing references to do_action/apply_filters

Nikolay Bachiyski nbachiyski at developer.bg
Thu Aug 4 09:20:53 GMT 2005

In newer default php.ini setups the value of

allow_call_time_pass_reference (see http://uk2.php.net/ini.core)

is Off, which does not allow to pass arguments by reference unless it is 
explicitly noted in the function's declaration.

However, sometimes is is needed a hook to change the values of its 
arguments. For example see the patch for pre_ping hook 
(http://trac.wordpress.org/ticket/1489 and 
http://trac.wordpress.org/changeset/2743 ) and if 
allow_call_time_pass_reference is Off it causes a Warning: "Warning: 
Call-time pass-by-reference has been deprecated.." (see 

Unfortunately there isn't an easy way to control whether 
do_action/apply_filter arguments are passed by reference of by value.

Of course there are some dirty hacks, as for example using an array to 
pass all the variables:

function varargs_by_ref($arg_list = null) {
	if (is_array($arg_list)) {
		foreach ($arg_list as &$arg) {
			# do whatever you want with $arg...

$by_ref = 'to_be_midified_inside_func';
$by_val = 'to_be_passed_by_value';

varargs_by_ref(array('baba', &$by_ref, $by_value));


Any other suggestions?


More information about the wp-hackers mailing list