|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #4116 array_walk allows userdata to be passed by ref but only half works
Submitted: 2000-04-12 09:45 UTC Modified: 2000-06-15 21:25 UTC
From: alexphpbug at blamey dot freeserve dot co dot uk Assigned: venaas (profile)
Status: Closed Package: Misbehaving function
PHP Version: 4.0 Beta 4 Patch Level 1 OS: Redhat linux 6.0 i386 SMP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: alexphpbug at blamey dot freeserve dot co dot uk
New email:
PHP Version: OS:


 [2000-04-12 09:45 UTC] alexphpbug at blamey dot freeserve dot co dot uk
The following code demonstrates the 'feature' ...

function myfunc(&$value, $key, &$user) {
	$value = "$user:$value";
	printf("%3d : %s\n", $key, $value);

$myarray=array("one", "two", "three");
array_walk($myarray, "myfunc", $myvar);
echo "myvar=$myvar";

This code outputs the following ...

  0 : 1:one
  1 : 2:two
  2 : 3:three

myvar has been incremented between calls within array_walk but the final
value is not passed back to the original variable.

I understand that the above usage is not mentioned in the docs but it would
be a nice feature to have.  The current functionality seems to be somewhat
inconsistent and I doubt its usefulness.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2000-06-15 21:25 UTC] venaas at cvs dot php dot net
It works like it should I think. What happens is that the array_walk
function gets a copy of $myvar. myfunc then gets a reference to
this copy. If you call array_walk with &$myvar it does what you want.


PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Dec 04 09:03:37 2021 UTC