[wp-hackers] Question about do_action & its handling of arguments

Claude Needham gxxaxx at gmail.com
Wed Jul 27 16:41:58 UTC 2011

Can someone provide a little insight on why do_action is handling
arguments in the following fashion?

386	        $args = array();
387	        if ( is_array($arg) && 1 == count($arg) && isset($arg[0])
&& is_object($arg[0]) ) // array(&$this)
388	                $args[] =& $arg[0];
389	        else
390	                $args[] = $arg;

It looks to me like the fundamental nature of the argument I am
passing changes depending upon the count.

This means that when I use foreach in the action handling  function
the nature of the iteration changes depending upon the count.

I would have expected the arguments to passed through the function in
a transparent fashion.

I'm curious what situation is being made easier by do_action's current
approach to handling arguments.
And, I'd like to know the best practices for handling the argment in
order to account for its change depending upon the count of the
original array.


More information about the wp-hackers mailing list