ID:               47554
 User updated by:  jimmy at basicmatrix dot com
 Reported By:      jimmy at basicmatrix dot com
 Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: Linux
 PHP Version:      5.2.9
 New Comment:

I never knew that functions/methods that fail parameter validation will
always return NULL. Thanks for clearing that up for me!

But how is it that an uncallable callback is detected as a parameter
failure during the internal parameter validation? I would think it would
be checking for $callback to be a "string" or "array(2)" (vs. something
obviously wrong, i.e., a "resource"). After that, the check for an
invalid callback would be detected once call_user_func_array() attempts
to call it. In which case, it would "fail" to complete its task and
return FALSE.

If the "callback" type is validated fully outside of
call_user_func_array()'s control--and if the change I'm suggesting is
impossible to make, i.e., if other functions besides call_user_func*()
will crash if given an invalid callback--could the documentation for
call_user_func* be updated to read:

"Returns the function result, NULL for an invalid callback, and FALSE
for all other errors."?

That addition would have saved me a lot of development time. My code
was expecting FALSE from call_user_func_array() OR the callback to mean
"stop the callback loop" for any reason. (NULL from the callback
function is acceptable.) I have fixed my code by calling the
is_callable() function first.

Thank for your help!


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

[2009-03-04 10:14:51] [email protected]

Calling a function/method with invalid parameter, eg. parameters that
does not pass parameter parsing internally all return NULL. In this case
FALSE is returned if something fails after the parameter parsing have
passed.

------------------------------------------------------------------------

[2009-03-03 23:47:58] jimmy at basicmatrix dot com

Description:
------------
call_user_func_array() claims it "Returns the function result, or FALSE
on error."

My testing shows it returns NULL if the callback function is not a
valid callback.

Reproduce code:
---------------
<?php

function callable()
{       return 'Good.'; }

$return = call_user_func_array('callable',array());
var_dump($return);

$return = call_user_func_array('not_callable',array());
var_dump($return);

?>

Expected result:
----------------
string(5) "Good."
Warning: call_user_func_array() [function.call-user-func-array]: First
argument is expected to be a valid callback, 'not_callable' was given in
_______ on line 9
FALSE

Actual result:
--------------
string(5) "Good."
Warning: call_user_func_array() [function.call-user-func-array]: First
argument is expected to be a valid callback, 'not_callable' was given in
_______ on line 9
NULL


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=47554&edit=1

Reply via email to