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
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.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 07:01:31 2024 UTC