Bug #2288: array_walk() not passing all parameters to called function

From: Date: Mon, 13 Sep 1999 21:18:00 +0000
Subject: Bug #2288: array_walk() not passing all parameters to called function
Groups: php.dev 
Request: Send a blank email to php-dev+get-10868@lists.php.net to get a copy of this message
From: matt@primefactor.com Operating system: Linux PHP version: 3.0.12 PHP Bug Type: Misbehaving function Bug description: array_walk() not passing all parameters to called function The documentation for array_walk() states that the function being called will be passed two parameters; specifically it states, "func will be passed array value as the first parameter and array key as the second parameter." array_walk() is passing the first parameter but is failing to pass the second one which is the key. The example code supplied at http://www.php.net/manual/function.array-walk.php3 gives the following errors: Warning: Missing argument 2 in call to test_print() in /usr/local/apache/htdocs/test.php on line 8 . lemon Warning: Missing argument 2 in call to test_print() in /usr/local/apache/htdocs/test.php on line 8 . orange Warning: Missing argument 2 in call to test_print() in /usr/local/apache/htdocs/test.php on line 8 . banana Warning: Missing argument 2 in call to test_print() in /usr/local/apache/htdocs/test.php on line 8 . apple for the following code from the array_walk() documentation page: <?php $fruits = array("d"=>"lemon","a"=>"orange","b"=>"banana","c"=>"apple"); function test_alter( &$item1, $key, $prefix ) { $item1 = "$prefix: $item1"; } function test_print( $item2, $key ) { echo "$key. $item2<br>\n"; } array_walk( $fruits, 'test_print' ); // array_walk( $fruits, 'test_alter', 'fruit' ); // array_walk( $fruits, 'test_print' ); ?> This seems to be a bug as the documentation states that the value and key are passed to the function specified in array_walk(). However, only the value is being passed while the key is omitted.

« previous php.dev (#10868) next »