php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #2713 array_walk() only calls user function with 1 param
Submitted: 1999-11-12 15:05 UTC Modified: 1999-11-12 15:11 UTC
From: joey at samaritan dot com Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.12 OS: Solaris 2.6, Debian Linux (2.2 K
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: joey at samaritan dot com
New email:
PHP Version: OS:

 

 [1999-11-12 15:05 UTC] joey at samaritan dot com
According to docs:
 func will be passed array value as the first parameter and array key as the second parameter.

This is not happening.
<?
error_reporting(15);
$fruits = array("d"=>"lemon","a"=>"orange","b"=>"banana","c"=>"apple");

function test_alter( &$item1, $key, $prefix ) {
   $item1 = "$prefix: $item1";
}

function test_print( $val, $key ) {
//function test_print( $val ) {
   echo "$key. $val\n";
}

array_walk( $fruits, 'test_print' );
array_walk( $fruits, 'test_alter', 'fruit' );
array_walk( $fruits, 'test_print' );
?>

Should get:
d. lemon
a. orange
b. banana
c. apple
d. fruit: lemon
a. fruit: orange
b. fruit: banana
c. fruit: apple

I think the problem is related to this, from functions/basic_functions.c(1630?):
static int _php3_array_walk(const void *a)
{
        pval *args[1];
        pval retval;

        args[0] = (pval *)a;
        
        call_user_function(&GLOBAL(function_table), NULL, php3_array_walk_func_name, &retval, 1, args);
        return 0;
}

The user function should expect at LEAST 2 args, but "a" contains only one argument.
Sadly, I could not see my way through a patch for this (but I _REALLY_ tried! :)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-11-12 15:11 UTC] andrei at cvs dot php dot net
Only PHP 4 supports passing more than 1 parameter to the user function.
I will amend the documentation.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 07 07:01:33 2025 UTC