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

 ID:                 62264
 Updated by:         [email protected]
 Reported by:        marti dot markov at gmail dot com
 Summary:            array_walk not changeing keys
-Status:             Open
+Status:             Not a bug
 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:

As Sjon mentioned this is not a bug. You can't change they key in the callback. 
You generally can't change the key in a dictionary without a) removing the old 
key and b) inserting the value under a new key. This behavior is inherent to 
dictionaries.


Previous Comments:
------------------------------------------------------------------------
[2012-06-08 12:41:55] Sjon at hortensius dot net

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

------------------------------------------------------------------------
[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

Reply via email to