Edit report at http://bugs.php.net/bug.php?id=52244&edit=1

 ID:               52244
 Updated by:       johan...@php.net
 Reported by:      davidcanos at gmail dot com
 Summary:          array_walk 3rd parameter not modifying by-reference
-Status:           Open
+Status:           Bogus
 Type:             Bug
 Package:          Arrays related
 Operating System: Windows
 PHP Version:      5.3.2

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2010-07-04 13:11:38] 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 



------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52244&edit=1

Reply via email to