array_map in conjunction with user_call_func_array - inconsistency

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



listers,

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'?


===========================================================================

function array_map_assoc($callback, $arr)
{
    $keys = array_keys($arr);
    $args = func_get_args();

    $arr = call_user_func_array("array_map", $args);

    /* return the fixed array */
    return $arr;
}

// couldn't figure out how else
// to use a single quote with php -r in a bash shell
$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>" ));


echo "-----\n\n"; var_dump($arr1, $arr2, $arr3, $arr4, $arr5);


===========================================================================


OUTPUTS ON 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""" }



rgds,
Jochem

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux