From: dharma dot yp at in dot ibm dot com Operating system: Windows, Linux PHP version: 6CVS-2007-12-11 (snap) PHP Bug Type: Arrays related Bug description: array_walk() & array_walk_recursive() return value not as documented.
Description: ------------ The return value returned by array_walk() and array_walk_recursive() not as per the documentation. As per the documentation when these function fail it is expected to return FALSE, but it returns different values. Documentation links: http://in.php.net/manual/en/function.array-walk.php http://in.php.net/manual/en/function.array-walk-recursive.php Below are two scenarios where return value differ : 1) When function is called with nonexistent callback function, it returns NULL (expected value is bool(false) ) as return value along with warning message(warning message as expected) 2)When there are less number of arguments passed for the callback function then it return bool(true) along with a warning message. As we notice the function does get called and the code is executed, hence should it be considered as complete and return value be bool(true) ? or since there is a warning indicating that there were problem and the return value be bool(false) ? It would be nice to have consistent return value & sync the code with the documentation or documentation with the current code. Reproduce code: --------------- <?php function actual_function($index, $key, $user_data) { echo "callback function called\n"; } $input = array( array(1), array(3)); var_dump( array_walk($input, "non_existent")); var_dump( array_walk($input, "actual_function")); var_dump( array_walk_recursive($input, "non_existent")); var_dump( array_walk_recursive($input, "actual_function")); ?> Expected result: ---------------- Warning: array_walk() expects parameter 2 to be valid callback, string given in %s on line %d bool(false) Warning: Missing argument 3 for actual_function() in %s on line %d bool(false) Warning: array_walk_recursive() expects parameter 2 to be valid callback, string given in %s on line %d bool(false) Warning: Missing argument 3 for actual_function() in %s on line %d bool(false) Warning: Missing argument 3 for actual_function() in %s on line %d bool(false) Actual result: -------------- Warning: array_walk() 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 callback function called bool(true) 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 callback function called bool(true) Warning: Missing argument 3 for actual_function() in %s on line %d callback function called bool(true) -- Edit bug report at http://bugs.php.net/?id=43558&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43558&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43558&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43558&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43558&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=43558&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=43558&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=43558&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=43558&r=needscript Try newer version: http://bugs.php.net/fix.php?id=43558&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=43558&r=support Expected behavior: http://bugs.php.net/fix.php?id=43558&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=43558&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=43558&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=43558&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43558&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=43558&r=dst IIS Stability: http://bugs.php.net/fix.php?id=43558&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=43558&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=43558&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=43558&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=43558&r=mysqlcfg
