ID: 45780 Updated by: [EMAIL PROTECTED] Reported By: Ultrasick at gmx dot de -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: probably any PHP Version: 5.2.6 New Comment:
Previous Comments: ------------------------------------------------------------------------ [2008-08-11 18:22:29] [EMAIL PROTECTED] This is expected. > array_walk($my_array, 'my_function', $my_variable); The variable is passed by reference to my_function(), you can verify that by adding an echo in the function. But as you did not passed $my_variable by reference, array_walk() uses its own copy of $my_variable, and this is that copy which is passed to my_function(). So you need to pass it explicitly by reference to array_walk(). ------------------------------------------------------------------------ [2008-08-11 03:45:45] Ultrasick at gmx dot de Description: ------------ The function "array_walk" ignores to pass the reference and passes the content instead for the parameter "userdata" if the "&" isn't written inside the "array_walk()" but inside the function definition ("function somename(&$value, &$key, &$userdata)"). This doesn't work for the "userdata"-parameter but it does work for the "value" and the "key"-parameter. Have a look at the code at the bottom and the expected and the actual result. Now compare what would happen if you would call "my_function" manually by using my_function($any_value, $any_key, $my_variable); echo $my_variable; and then using my_function($any_value, $any_key, &$my_variable); echo $my_variable; In both cases $my_variable would be increased, of course. So in my oppinion the userdata-problem it's not just inconsistency. It's a bug because a part of the function definition is beeing ignored. Reproduce code: --------------- <? function my_function(&$value, &$key, &$userdata){ $userdata++; } $my_array = array('one', 'two', 'three'); $my_variable = 1; array_walk($my_array, 'my_function', $my_variable); echo $my_variable; echo '<p><hr></p>'; array_walk($my_array, 'my_function', &$my_variable); echo $my_variable; ?> Expected result: ---------------- expected output: 4 ----------- 4 Actual result: -------------- actual output: 1 ----------- 4 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45780&edit=1