php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #2288 array_walk() not passing all parameters to called function
Submitted: 1999-09-13 17:18 UTC Modified: 1999-09-14 03:13 UTC
From: matt at primefactor dot com Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.12 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: matt at primefactor dot com
New email:
PHP Version: OS:

 

 [1999-09-13 17:18 UTC] matt at primefactor dot com
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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-09-14 03:06 UTC] thies at cvs dot php dot net
new functionality in 4.0.

 [1999-09-14 03:13 UTC] thies at cvs dot php dot net
to clearify:
this functionality was added in 4.0

we should update the docs to reflect this.

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 21:01:35 2025 UTC