Bug #52244 [Opn->Bgs]: array_walk 3rd parameter not modifying by-reference
| From: | johannes@php.net | Date: | Thu, 08 Jul 2010 11:03:57 +0000 |
| Subject: | Bug #52244 [Opn->Bgs]: array_walk 3rd parameter not modifying by-reference | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-152219@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52244&edit=1
ID: 52244
Updated by: johannes@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