inconsistent return value from array_map() when used with call_user_func_array()

From: Date: Sat, 05 Feb 2005 14:33:50 +0000
Subject: inconsistent return value from array_map() when used with call_user_func_array()
Groups: php.internals 
Request: Send a blank email to internals+get-14650@lists.php.net to get a copy of this message
Hi devs, I was playing around with call_user_func_array() and array_map() on PHP 5.0.2 (cli) (built: Nov 9 2004 19:00:36) and noticed the that calling call_user_func_array() on 'array_map' with more than 2 args (i.e. more than just the name of the callback and array argument that are required for 'array_map') then a numerically indexed array is returned, where as with just the minimum 2 args the associative keys of array are maintained: question is have I missed something, am I doing something wrong or it this a 'buglet'? (I haven't been able to find anything in the bugs DB regarding this) [I originally posted this on generally but got no response.] =========================================================================== function array_map_assoc($callback, $arr) {
    $args = func_get_args();
    return call_user_func_array("array_map", $args);
} $sq = chr(39); // start array
$arr1 = array(    "name" => "\"{$sq}Testing{$sq}\"",
        "email" => "\"Yadda{$sq}s \"YADDa\"<script language={$sq}Testing{$sq} source={$sq}{$sq}></script>\"");
$arr2 = array_map_assoc("strip_tags", $arr1); $arr3 = array_map_assoc("htmlentities", $arr2, array( ENT_QUOTES, ENT_QUOTES )); $arr4 = array_map_assoc("htmlentities", $arr2); $arr5 = array_map_assoc("strip_tags", $arr1, array( "<p>", "<p>" )); // test without array_map_assoc $arr6 = call_user_func_array("array_map", array("strip_tags", $arr1, array( "<p>", "<p>" ))); echo "-----\n\n"; var_dump($arr1, $arr2, $arr3, $arr4, $arr5, $arr6); =========================================================================== OUTPUTS (on my machine): ----- array(2) { ["name"]=> string(11) ""'Testing'"" ["email"]=> string(63) ""Yadda's "YADDa"<script language='Testing' source=''></script>"" } array(2) { ["name"]=> string(11) ""'Testing'"" ["email"]=> string(17) ""Yadda's "YADDa""" } array(2) { [0]=> string(31) "&quot;&#039;Testing&#039;&quot;" [1]=> string(42) "&quot;Yadda&#039;s &quot;YADDa&quot;&quot;" } array(2) { ["name"]=> string(21) "&quot;'Testing'&quot;" ["email"]=> string(37) "&quot;Yadda's &quot;YADDa&quot;&quot;" } array(2) { [0]=> string(11) ""'Testing'"" [1]=> string(17) ""Yadda's "YADDa""" } array(2) { [0]=> string(11) ""'Testing'"" [1]=> string(17) ""Yadda's "YADDa""" } rgds, Jochem

« previous php.internals (#14650) next »