#36997 [NEW]: array_map() fails when array is passed to callback function by reference

From: Date: Thu, 06 Apr 2006 15:21:03 +0000
Subject: #36997 [NEW]: array_map() fails when array is passed to callback function by reference
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-95382@lists.php.net to get a copy of this message
From: o dot veujoz at free dot fr Operating system: Windows PHP version: 5.1.2 PHP Bug Type: Arrays related Bug description: array_map() fails when array is passed to callback function by reference Description: ------------ Problem with array_map() function : With php 5.0.4, when we pass an array to callback function by reference, the function modifies its arguments. It is not the case with php 5.1.2. I read the bug number 33940 where "Dmitry" wrote : "To make array_map() work as you expected you should pass arrays by reference directly." So there is apparently a solution. I did try a lot of changes in my script but no one works as expected. For example, the code below works fine in PHP 5.1.2 but an error is generated in PHP 5.0.4 : array_map('callback', &$arr); The only way to make the script works on both PHP versions has been consisting in not using the parameters passed by reference (it does not correspond to the original problem). $arr = array_map('callback', $arr); Is it really a bug or is my code bad ? Note: the allow_call_time_pass_reference has been turned off in both PHP versions. Reproduce code: --------------- function callback(&$val) { $val['TEST'] = 'new value'; } $arr = array(0 => array ('TEST' => 'foo')); array_map('callback', $arr); print_r($arr); Expected result: ---------------- Array ( [0] => Array ( [TEST] => new value ) ) Actual result: -------------- Array ( [0] => Array ( [TEST] => foo ) ) -- Edit bug report at http://bugs.php.net/?id=36997&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=36997&r=trysnapshot44 Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=36997&r=trysnapshot51 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=36997&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=36997&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=36997&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=36997&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=36997&r=needscript Try newer version: http://bugs.php.net/fix.php?id=36997&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=36997&r=support Expected behavior: http://bugs.php.net/fix.php?id=36997&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=36997&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=36997&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=36997&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36997&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=36997&r=dst IIS Stability: http://bugs.php.net/fix.php?id=36997&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=36997&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=36997&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=36997&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=36997&r=mysqlcfg

« previous php.bugs (#95382) next »