#47554 [Bgs]: call_user_func_array returns NULL (instead of FALSE) for invalid callbacks

2009-03-04 Thread jimmy at basicmatrix dot com
 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] ka...@php.net

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=47554edit=1



#47554 [NEW]: call_user_func_array returns NULL (instead of FALSE) for invalid callbacks

2009-03-03 Thread jimmy at basicmatrix dot com
From: jimmy at basicmatrix dot com
Operating system: Linux
PHP version:  5.2.9
PHP Bug Type: Scripting Engine problem
Bug description:  call_user_func_array returns NULL (instead of FALSE) for 
invalid callbacks

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 bug report at http://bugs.php.net/?id=47554edit=1
-- 
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=47554r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=47554r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=47554r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=47554r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=47554r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=47554r=alreadyfixed
Need backtrace:  
http://bugs.php.net/fix.php?id=47554r=needtrace
Need Reproduce Script:   
http://bugs.php.net/fix.php?id=47554r=needscript
Try newer version:   
http://bugs.php.net/fix.php?id=47554r=oldversion
Not developer issue: 
http://bugs.php.net/fix.php?id=47554r=support
Expected behavior:   
http://bugs.php.net/fix.php?id=47554r=notwrong
Not enough info: 
http://bugs.php.net/fix.php?id=47554r=notenoughinfo
Submitted twice: 
http://bugs.php.net/fix.php?id=47554r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=47554r=globals
PHP 4 support discontinued:  http://bugs.php.net/fix.php?id=47554r=php4
Daylight Savings:http://bugs.php.net/fix.php?id=47554r=dst
IIS Stability:   
http://bugs.php.net/fix.php?id=47554r=isapi
Install GNU Sed: 
http://bugs.php.net/fix.php?id=47554r=gnused
Floating point limitations:  
http://bugs.php.net/fix.php?id=47554r=float
No Zend Extensions:  
http://bugs.php.net/fix.php?id=47554r=nozend
MySQL Configuration Error:   
http://bugs.php.net/fix.php?id=47554r=mysqlcfg