Bug #2713: array_walk() only calls user function with 1 param

From: Date: Fri, 12 Nov 1999 20:05:51 +0000
Subject: Bug #2713: array_walk() only calls user function with 1 param
Groups: php.dev 
Request: Send a blank email to php-dev+get-12396@lists.php.net to get a copy of this message
From: joey@samaritan.com Operating system: Solaris 2.6, Debian Linux (2.2 Kernel) PHP version: 3.0.12 PHP Bug Type: Misbehaving function Bug description: array_walk() only calls user function with 1 param 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! :)

« previous php.dev (#12396) next »