[wp-trac] Re: [WordPress Trac] #2584: do_action merges array args,
causing data loss prior to callback
WordPress Trac
wp-trac at lists.automattic.com
Wed Mar 22 02:17:43 GMT 2006
#2584: do_action merges array args, causing data loss prior to callback
----------------------------+-----------------------------------------------
Id: 2584 | Status: new
Component: Administration | Modified: Wed Mar 22 02:17:43 2006
Severity: normal | Milestone:
Priority: normal | Version: 2.0.2
Owner: anonymous | Reporter: skeltoac
----------------------------+-----------------------------------------------
Comment (by random):
It's not '''broken''', just counterintuitive. Virtually everywhere else in
the code where arrays are sent, the behaviour is intended. e.g.,
{{{
do_action('wp_authenticate', array(&$user_login, &$user_pass));
}}}
Should have a callback like
{{{
function my_auth($login, $pass) // ...
}}}
The array behaviour can't be changed without breaking plugins using those
hooks. If the behaviour is undesirable, by all means discuss changing it.
I just don't think it's bad enough to warrant breaking backwards
compatibility over.
David:
{{{
do_action('myaction',
array('a' => 1, 'b' => 2, 'c' => 3),
array('d' => 4, 'e' => 5)
);
}}}
get_func_args() in the callback returns this:
{{{
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => Array
(
[d] => 4
[e] => 5
)
)
}}}
But what gets passed to call_user_func_array() is this:
{{{
Array
(
[a] => 1
[b] => 2
[c] => 3
[0] => Array
(
[d] => 4
[e] => 5
)
)
}}}
No data is lost by the merge, it's just inaccessible to the function since
call_user_func_array() discards the keys.
The workaround is just to pass an array of arrays as the first argument,
like the #2553 patch does.
{{{
do_action('myaction', array(
array('a' => 1, 'b' => 2, 'c' => 3),
array('d' => 4, 'e' => 5)
) );
}}}
--
Ticket URL: <http://trac.wordpress.org/ticket/2584>
WordPress Trac <http://wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list