Home » PHP » PHP_Compat » Bug #9659
The userdata parameter isn't correctly send to the recursive call
Details
| Request #9659 | The userdata parameter isn't correctly send to the recursive call |
|---|---|
| Submitted | 2006-12-19 17:44 UTC |
| From | jean-philippe dot goydadin at rve dot ulaval dot ca |
| Assigned | arpad |
| Status | Closed |
| Package | PHP_Compat |
| PHP Version | 4.4.4 |
| OS | Windows |
| Roadmaps | 1.6.0a1 |
Comments
[2006-12-19 17:44 UTC] jean-philippe dot goydadin at rve dot ulaval dot ca
Description:
------------
Why the recursive call of array_walk_recursive() doesn't the exact parameter it needs ? The first and second arguments are OK ($item and $funcname) but the third give the complete array , so the function receive $item and $funcname and an array containing $item, $funcname and the $userdata variable.
Then in the funcname function, if you use the $userdata parameter, you have to think that the parameters is the array and the $userdata is the third value of this array !
Test script:
---------------
// Line 56 of the code in the 1.7 version
// array_walk_recursive($item, $funcname, $args);
// My proposition
// array_walk_recursive($item, $funcname, $args[2]);
// function to call
function test_userdata(&$item, $key, $userdata)
{
$item = $userdata . ' - ' . $item;
}
$a = array(array('test11', 'test12', 'test13'), 'test2', array('test31', 'test32'));
array_walk_recursive($a, 'test_userdata', 'print userdata');
print_r($a);
Expected result:
----------------
Array
(
[0] => Array
(
[0] => print userdata - test11
[1] => print userdata - test12
[2] => print userdata - test13
)
[1] => print userdata - test2
[2] => Array
(
[0] => print userdata - test31
[1] => print userdata - test32
)
)
Actual result:
--------------
Array
(
[0] => Array
(
[0] => Array - test11
[1] => Array - test12
[2] => Array - test13
)
[1] => print userdata - test2
[2] => Array
(
[0] => Array - test31
[1] => Array - test32
)
)