php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
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' ...

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

$myarray=array("one", "two", "three");
$myvar=1;
array_walk($myarray, "myfunc", $myvar);
echo "myvar=$myvar";
</CODE>

This code outputs the following ...

<SAMP>
  0 : 1:one
  1 : 2:two
  2 : 3:three
myvar=1
</SAMP>

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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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.

Stig

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