php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53736 array_walk key reference
Submitted: 2011-01-13 14:48 UTC Modified: 2011-01-13 16:02 UTC
From: samuel dot roze at gmail dot com Assigned:
Status: Wont fix Package: Arrays related
PHP Version: 5.3.5 OS: Redhat 5
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: samuel dot roze at gmail dot com
New email:
PHP Version: OS:

 

 [2011-01-13 14:48 UTC] samuel dot roze at gmail dot com
Description:
------------
The keys of arrays should be accessible by reference into walking functions. See the scripts below:

Test script:
---------------
$array = array(
        'COL1' => 'VALue1',
        'COL2' => '2',
        'COL4' => 'valUE3'
);
var_dump($array);

$walk = array_walk($array, function (&$value, &$key) {
        $key = strtolower($key);
        $value = strtolower($value);
});
var_dump($walk, $array);

Expected result:
----------------
array
  'COL1' => string 'VALue1' (length=6)
  'COL2' => string '2' (length=1)
  'COL4' => string 'valUE3' (length=6)

boolean true

array
  'col1' => string 'value1' (length=6)
  'col2' => string '2' (length=1)
  'col4' => string 'value3' (length=6)


Actual result:
--------------
array
  'COL1' => string 'VALue1' (length=6)
  'COL2' => string '2' (length=1)
  'COL4' => string 'valUE3' (length=6)

boolean true

array
  'COL1' => string 'value1' (length=6)
  'COL2' => string '2' (length=1)
  'COL4' => string 'value3' (length=6)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-13 16:02 UTC] cataphract@php.net
-Status: Open +Status: Wont fix
 [2011-01-13 16:02 UTC] cataphract@php.net
Array keys are not proper PHP values, so this is not possible.

There is no reasonable way to handle a callback function that did:

function (&$value, &$key) {
        $key = function () {};
        //or $key = array();
}
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC