ID:               43558
 User updated by:  dharma dot yp at in dot ibm dot com
 Reported By:      dharma dot yp at in dot ibm dot com
 Status:           Open
 Bug Type:         Arrays related
 Operating System: Windows, Linux
 PHP Version:      6CVS-2007-12-11 (snap)
 New Comment:

This problem is also there with PHP5.3


Previous Comments:
------------------------------------------------------------------------

[2007-12-11 05:01:27] dharma dot yp at in dot ibm dot com

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 this bug report at http://bugs.php.net/?id=43558&edit=1

Reply via email to