| Bug #33940 | array_map() fails to pass by reference when called recursively | ||||
|---|---|---|---|---|---|
| Submitted: | 2005-08-01 05:05 UTC | Modified: | 2005-08-10 10:24 UTC | ||
| From: | david dot tulloh at infaze dot com dot au | Assigned: | dmitry (profile) | ||
| Status: | Closed | Package: | Arrays related | ||
| PHP Version: | 5CVS-2005-08-02 | OS: | * | ||
| Private report: | No | CVE-ID: | None | ||
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 )