|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-06-27 23:21 UTC] richard@php.net
Description:
------------
When a function called by call_user_func_array() throws an exception, an error appears: "Warning: call_user_func_array() [function.call-user-func-array]: Unable to call babba() in /data/webdev/classes/Tree/demo.php on line 19"
Reproduce code:
---------------
<?php
function babba()
{
throw new Exception('foo');
}
try {
call_user_func_array('babba', array());
} catch (Exception $e) {
// Eek
}
?>
Expected result:
----------------
Nothing
Actual result:
--------------
Warning: call_user_func_array() [function.call-user-func-array]: Unable to call babba() in /data/webdev/classes/Tree/demo.php on line 43
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 18:00:01 2025 UTC |
I ran the following to see if the exception was being thrown. It is thrown and caught: Reproduce code: --------------- <?php function foo() { throw new Exception('bar'); } try { call_user_func_array('foo', array()); } catch (Exception $e) { echo $e->getMessage(); } // Expected output: bar ?> Actual result: -------------- Warning: call_user_func_array() [function.call-user-func-array]: Unable to call foo() in /path/to/test.php on line 16 bar Extended Info: -------------- I also attempted catching an exception with call_user_func() - it worked as expected producing only "bar". I also produced an identical outcome when I used a non-empty array as the second argument. This is most definitely an issue with call_user_func_array(). The following code produces a similar error: Reproduce code: --------------- <?php assert_options( ASSERT_CALLBACK, 'throwException' ); function foo() { assert( false ); throw new Exception('bar'); } function throwException( ) { throw new Exception('assert'); } try { call_user_func_array('foo', array(0, 1)); } catch (Exception $e) { echo $e->getMessage(); } // Expected Output: assert ?> Actual results: --------------- Warning: assert() [function.assert]: Assertion failed in /path/to/test.php on line 7 Warning: call_user_func_array() [function.call-user-func-array]: Unable to call foo() in /path/to/test.php on line 20 assert More Info: ---------- Bug #29617 seems to be a duplicate of this report.This is still present in PHP 5.0.2. I've created a patch file. Just save it as php-5.0.2/call_user_func_array.patch and run "patch -p0 < call_user_func_array.patch" from within php-5.0.2/. ----- Begin Patch ----- diff -Naur ../php-5.0.2/ext/standard/basic_functions.c ./ext/standard/basic_functions.c --- ../php-5.0.2/ext/standard/basic_functions.c 2004-08-19 10:15:32.000000000 -0500 +++ ./ext/standard/basic_functions.c 2004-09-24 13:48:58.000000000 -0500 @@ -1988,8 +1988,10 @@ current++; } - if (call_user_function_ex(EG(function_table), NULL, *func, &retval_ptr, count, func_params, 0, NULL TSRMLS_CC) == SUC CESS && retval_ptr) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); + if (call_user_function_ex(EG(function_table), NULL, *func, &retval_ptr, count, func_params, 0, NULL TSRMLS_CC) == SUC CESS ) { + if (retval_ptr) { + COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); + } } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s()", name); } ----- End Patch -----