|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-12-10 09:45 UTC] jani@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 13 09:00:01 2025 UTC |
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)