#33940 [NEW]: array_map fails to pass by reference when called recursively

From: Date: Mon, 01 Aug 2005 03:05:51 +0000
Subject: #33940 [NEW]: array_map fails to pass by reference when called recursively
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-82746@lists.php.net to get a copy of this message
From: david dot tulloh at infaze dot com dot au Operating system: Debian Linux PHP version: 5CVS-2005-08-01 (dev) PHP Bug Type: Arrays related Bug description: array_map fails to pass by reference when called recursively Description: ------------ array_map fails to work recursively. It does not pass by reference in the inner array_map call. Changing the line to $ret = array_map('ref_map', &$item); provides the expected result but throws a Call-time pass-by-reference warning. Reproduce code: --------------- <?php function ref_map(&$item) { if(!is_array($item)) { $item = 1; return 2; } else { $ret = array_map('ref_map', $item); echo 'Inner return: '; print_r($ret); echo 'Inner item: '; print_r($item); return $ret; } } $a = array(array(0), 0); $ret = array_map('ref_map', $a); echo 'Array: '; print_r($a); echo 'Return: '; print_r($ret); ?> Expected result: ---------------- Inner return: Array ( [0] => 2 ) Inner item: Array ( [0] => 1 ) Array: Array ( [0] => Array ( [0] => 1 ) [1] => 1 ) Return: Array ( [0] => Array ( [0] => 2 ) [1] => 2 ) Actual result: -------------- Inner return: Array ( [0] => 2 ) Inner item: Array ( [0] => 0 ) Array: Array ( [0] => Array ( [0] => 0 ) [1] => 1 ) Return: Array ( [0] => Array ( [0] => 2 ) [1] => 2 ) -- Edit bug report at http://bugs.php.net/?id=33940&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33940&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=33940&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=33940&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=33940&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=33940&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=33940&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=33940&r=needscript Try newer version: http://bugs.php.net/fix.php?id=33940&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=33940&r=support Expected behavior: http://bugs.php.net/fix.php?id=33940&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=33940&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=33940&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=33940&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33940&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=33940&r=dst IIS Stability: http://bugs.php.net/fix.php?id=33940&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=33940&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=33940&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=33940&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=33940&r=mysqlcfg

« previous php.bugs (#82746) next »