|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47554 call_user_func_array returns NULL (instead of FALSE) for invalid callbacks
Submitted: 2009-03-03 23:47 UTC Modified: 2009-03-04 15:43 UTC
From: jimmy at basicmatrix dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.9 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: jimmy at basicmatrix dot com
New email:
PHP Version: OS:


 [2009-03-03 23:47 UTC] jimmy at basicmatrix dot com
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:

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

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

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


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

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


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-04 10:14 UTC]
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-04 15:43 UTC] jimmy at basicmatrix dot com
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!
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Oct 03 13:01:25 2023 UTC