From: dharma dot yp at in dot ibm dot com Operating system: Windows, Linux PHP version: 5.2CVS-2007-12-09 (snap) PHP Bug Type: Arrays related Bug description: Misleading TRUE return value for array_walk() and array_walk_recursive().
Description: ------------ In array_walk() and array_walk_recursive() functions, 1) In PHP 5.2 , if we pass non-existent function( not defined), it is expected to output the warning message with return value "false".It is able output the warning message but not the correct return value. The warning message and return value is as follows. "Warning: array_walk(): Unable to call wrong_function() - function does not exist in %s on line %d bool(true)". Where as in PHP6, it works correct and warning message is as follows. "Warning: array_walk_recursive() : Expects parameter 2 to be valid callback, string given in %s on line %d NULL". 2) In PHP5.2, if we pass less number of parameters for "callback" function through the array_walk() call, it is expected to ouput the warning message with return value of "false". It is able to output the warning message but not the correct return value.The warning message and return value is as follows. "Warning: Missing argument 3 for actual_function() in %s on line %d bool(true)". This also fails with php 5.3 and php 6. The return value of " bool(true)" in (1) and (2) will misguide/confuse the developers as the documentation says array_walk()and array_walk_recursive()function calls return TRUE on Success and FALSE on Failure. Reproduce code: --------------- /**** for array_walk() ****/ <?php function actual_function($value, $key, $user_data) { echo $value + $key; } $input = array( 0 => 1, 1 => 2, 2 => 3); var_dump( array_walk($input, "wrong_function")); var_dump( array_walk($input, "actual_function")); ?> /**** for array_walk_recursive() ****/ function actual_function($value, $key, $user_data) { echo $value + $key; } $input = array( 0 => 1, 1 => 2, 2 => 3); var_dump( array_walk_recursive($input, "wrong_function")); var_dump( array_walk_recursive($input, "actual_function")); ?> Expected result: ---------------- /**** for array_walk() ****/ Warning: array_walk(): Unable to call wrong_function() - function does not exist in %s on line %d bool(false) Warning: Missing argument 3 for actual_function() in %s on line %d bool(false) /**** for array_walk_recursive() ****/ Warning: array_walk_recursive() : Expects parameter 2 to be valid callback, string given in %s on line %d NULL Warning: Missing argument 3 for actual_function() in %s on line %d bool(false) Actual result: -------------- /**** for array_walk() ****/ Warning: array_walk(): Unable to call wrong_function() - function does not exist in %s on line %d bool(true) Warning: Missing argument 3 for actual_function() in %s on line %d bool(true) /**** for array_walk_recursive() ****/ Warning: array_walk_recursive() : Expects parameter 2 to be valid callback, string given in %s on line %d NULL Warning: Missing argument 3 for actual_function() in %s on line %d bool(true) -- Edit bug report at http://bugs.php.net/?id=43543&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43543&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43543&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43543&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43543&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=43543&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=43543&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=43543&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=43543&r=needscript Try newer version: http://bugs.php.net/fix.php?id=43543&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=43543&r=support Expected behavior: http://bugs.php.net/fix.php?id=43543&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=43543&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=43543&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=43543&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43543&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=43543&r=dst IIS Stability: http://bugs.php.net/fix.php?id=43543&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=43543&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=43543&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=43543&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=43543&r=mysqlcfg