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

 ID:                 53736
 Updated by:         [email protected]
 Reported by:        samuel dot roze at gmail dot com
 Summary:            array_walk key reference
-Status:             Open
+Status:             Wont fix
 Type:               Feature/Change Request
 Package:            Arrays related
 Operating System:   Redhat 5
 PHP Version:        5.3.5
 Block user comment: N
 Private report:     N

 New Comment:

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();

}


Previous Comments:
------------------------------------------------------------------------
[2011-01-13 14:48:41] 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)


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



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

Reply via email to