php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52244 array_walk 3rd parameter not modifying by-reference
Submitted: 2010-07-04 13:11 UTC Modified: 2010-07-08 13:03 UTC
From: davidcanos at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.3.2 OS: Windows
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: davidcanos at gmail dot com
New email:
PHP Version: OS:

 

 [2010-07-04 13:11 UTC] davidcanos at gmail dot com
Description:
------------
third parameters of array_walk function is not changing unless I used the 
deprecated syntax of call-by-reference

Deprecated message is shown and its working properly that way.

Test script:
---------------
$cont  = 0;
$sampleArray = array(0,1,1,2,3,5,8,13);
$foo = function($item,$key,$aux){
	$aux++;	
};
array_walk($sampleArray,$foo,$cont);
echo $cont; // it's ok. cont = 0, no call-by-reference


echo "<hr>";

$cont  = 0;
$foo = function($item,$key,&$aux){
	$aux++;	
};
array_walk($sampleArray,$foo,$cont);
echo $cont; // it should be same as count($sampleArray) but it is 0 BUG!



echo "<hr>";


$cont  = 0;
$foo = function($item,$key,&$aux){
	$aux++;	
};
array_walk($sampleArray,$foo,&$cont);
echo $cont; // it is 8, perfect but Deprecated: Call-time pass-by-reference has been deprecated

Expected result:
----------------
0,8,8 should by right
but
0,0,8 


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-08 13:03 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2010-07-08 13:03 UTC] johannes@php.net
For doing this we'd have to implement array_walk not as a function but as some other form of language construct which won't happen. If you need to change that value you can either wrap it in a class or use a 5.3 closure as callback.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 19:01:35 2025 UTC