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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri May 10 16:01:32 2024 UTC