Fixed bug #33940 (array_map() fails to pass by reference when called recursively)

This commit is contained in:
Dmitry Stogov 2005-08-10 08:22:01 +00:00
parent 96d755978c
commit 54931f5259
3 changed files with 65 additions and 0 deletions

2
NEWS
View File

@ -19,6 +19,8 @@ PHP NEWS
(Jani)
- Fixed bug #33958 (duplicate cookies and magic_quotes=off may cause a crash).
(Ilia)
- Fixed bug #33940 (array_map() fails to pass by reference when called
recursively). (Dmitry)
- Fixed bug #33917 (number_format() output with > 1 char separators). (Jani)
- Fixed bug #33904 (input array keys being escaped when magic quotes is off).
(Ilia)

View File

@ -4252,6 +4252,7 @@ PHP_FUNCTION(array_map)
efree(array_pos);
return;
}
SEPARATE_ZVAL_IF_NOT_REF(pargs[i]);
args[i] = *pargs[i];
array_len[i] = zend_hash_num_elements(Z_ARRVAL_PP(pargs[i]));
if (array_len[i] > maxlen) {

View File

@ -0,0 +1,62 @@
--TEST--
Bug #33940 array_map() fails to pass by reference when called recursively
--INI--
error_reporting=4095
--FILE--
<?php
function ref_map(&$item) {
if(!is_array($item)) {
$item = 1;
return 2;
} else {
$ret = array_map('ref_map', &$item);
return $ret;
}
}
$a = array(array(0), 0);
$ret = array_map('ref_map', $a);
echo 'Array: '; print_r($a);
echo 'Return: '; print_r($ret);
$a = array(array(0), 0);
$ret = array_map('ref_map', &$a);
echo 'Array: '; print_r($a);
echo 'Return: '; print_r($ret);
?>
--EXPECT--
Array: Array
(
[0] => Array
(
[0] => 0
)
[1] => 0
)
Return: Array
(
[0] => Array
(
[0] => 2
)
[1] => 2
)
Array: Array
(
[0] => Array
(
[0] => 1
)
[1] => 1
)
Return: Array
(
[0] => Array
(
[0] => 2
)
[1] => 2
)