Bug #62264 [Com]: array_walk not changeing keys
| From: | Sjon at hortensius dot net | Date: | Fri, 08 Jun 2012 12:41:55 +0000 |
| Subject: | Bug #62264 [Com]: array_walk not changeing keys | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-171142@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62264&edit=1
ID: 62264
Comment by: Sjon at hortensius dot net
Reported by: marti dot markov at gmail dot com
Summary: array_walk not changeing keys
Status: Open
Type: Bug
Package: Arrays related
Operating System: Mac OS X
PHP Version: master-Git-2012-06-08 (Git)
Block user comment: N
Private report: N
New Comment:
The manual says "Only the values of the array may potentially be changed; .... If
the callback does not respect this requirement, the behavior of this function is
undefined, and unpredictable."
I think this could be a feature request, but not really a bug?
Also, your test-script is incomplete; but PHP's behavious is pretty consistent
regarding this functionality: http://3v4l.org/1dn4f
Previous Comments:
------------------------------------------------------------------------
[2012-06-08 09:32:25] marti dot markov at gmail dot com
Description:
------------
I have found this problem with 5.3.10 and got the latest GIT head revision and the problem was still
there.
When I try and change the value of the key it will not update it in the array, even though that I
use the key as a reference.
Test script:
---------------
$array = ( 'a' => 'Hello', 'b' => 'World');
array_walk($array, 'adda');
function adda(&$value, &$key) {
$key = "a".$key;
}
Expected result:
----------------
$array = ( 'aa' => 'Hello', 'ab' => 'World');
Actual result:
--------------
$array = ( 'a' => 'Hello', 'b' => 'World');
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62264&edit=1