|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-08-11 18:22 UTC] lbarnaud@php.net
[2008-08-11 22:48 UTC] Ultrasick at gmx dot de
[2008-08-11 23:03 UTC] Ultrasick at gmx dot de
[2008-08-11 23:22 UTC] lbarnaud@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 05:00:02 2025 UTC |
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