Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:14650 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32728 invoked by uid 1010); 5 Feb 2005 14:34:18 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 32701 invoked from network); 5 Feb 2005 14:34:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2005 14:34:17 -0000 X-Host-Fingerprint: 194.109.193.120 unknown Linux 2.4/2.6 Received: from ([194.109.193.120:59873] helo=mx1.moulin.nl) by pb1.pair.com (ecelerity HEAD (r4105:4106)) with SMTP id 68/16-34781-459D4024 for ; Sat, 05 Feb 2005 09:33:56 -0500 Received: from localhost (localhost [127.0.0.1]) by mx1.moulin.nl (Postfix) with ESMTP id C6889E4639 for ; Sat, 5 Feb 2005 15:33:57 +0100 (CET) Received: from mx1.moulin.nl ([127.0.0.1]) by localhost (moulin [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 05103-02 for ; Sat, 5 Feb 2005 15:33:55 +0100 (CET) Received: from [127.0.0.1] (localhost [127.0.0.1]) by mx1.moulin.nl (Postfix) with ESMTP id 0745DE4635 for ; Sat, 5 Feb 2005 15:33:54 +0100 (CET) Message-ID: <4204D94E.6040404@iamjochem.com> Date: Sat, 05 Feb 2005 15:33:50 +0100 User-Agent: Mozilla Thunderbird 0.9 (Windows/20041103) X-Accept-Language: en-us, en MIME-Version: 1.0 To: php internals X-Enigmail-Version: 0.89.5.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at moulin.nl Subject: inconsistent return value from array_map() when used with call_user_func_array() From: jochem@iamjochem.com (Jochem Maas) 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\"\""); $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( "

", "

" )); // test without array_map_assoc $arr6 = call_user_func_array("array_map", array("strip_tags", $arr1, array( "

", "

" ))); 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""" } array(2) { ["name"]=> string(11) ""'Testing'"" ["email"]=> string(17) ""Yadda's "YADDa""" } array(2) { [0]=> string(31) ""'Testing'"" [1]=> string(42) ""Yadda's "YADDa""" } array(2) { ["name"]=> string(21) ""'Testing'"" ["email"]=> string(37) ""Yadda's "YADDa""" } 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