PHP 4.0 Bug #4116: array_walk allows userdata to be passed by ref but only half works
| From: | alexphpbug at blamey dot freeserve dot co dot uk | Date: | Wed, 12 Apr 2000 13:45:02 +0000 |
| Subject: | PHP 4.0 Bug #4116: array_walk allows userdata to be passed by ref but only half works | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-17843@lists.php.net to get a copy of this message | ||
From: alexphpbug@blamey.freeserve.co.uk
Operating system: Redhat linux 6.0 i386 SMP
PHP version: 4.0 Beta 4 Patch Level 1
PHP Bug Type: Misbehaving function
Bug description: array_walk allows userdata to be passed by ref but only half works
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.