|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-08-11 16:58 UTC] jpbarrette at savoirfairelinux dot net
Description:
------------
If I throw an exception in a function previously called by
call_user_func_array, It produces a warning saying:
Unable to call (the function name)
But the function was correctly called. The same situation
doesn't occur if I use call_user_func instead.
Reproduce code:
---------------
<?php
function test($test) {
throw new Exception("This is a " . $test);
}
call_user_func_array("test", array("test"));
Expected result:
----------------
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 12:00:01 2025 UTC |
The fixed code: <?php function test($test) { throw new Exception("This is a " . $test); } call_user_func_array("test", array("test")); ?>i experienced this problem, too: Sample Code: ------------ <?php function foo() { throw new Exception(); } try { foo(); } catch(Exception $e) { echo __LINE__, '<br />'; } try { call_user_func('foo'); } catch(Exception $e) { echo __LINE__, '<br />'; } try { call_user_func_array('foo', array()); } catch(Exception $e) { echo __LINE__, '<br />'; } ?> Expected Result --------------- 11 17 23 Actual Result ------------- 11 17 Warning: call_user_func_array() [function.call-user-func-array]: Unable to call foo() in /home/eskaly/dev/test.php on line 27 23I've been running up against this blasted bug for some time in my test scripts - can't test for Exceptions without hard coding it. Anyhow, I just peeked under the hood and think I've got it squashed. file: ./ext/standand/basic_functions.c line 1984 - 1985 reads: if (call_user_function_ex(EG(function_table), NULL, *func, &retval_ptr, count, func_params, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) { COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); The cause of the bug seems to be the "&& retval_ptr" as an exception doesn't appear to return the same. It works when you adjust it to work like call_user_func() where it can succeed even if retval_ptr doesn't exist and/or is false. Modified ./ext/standand/basic_functions.c line 1984 - 1985 replaced to 1984 - 1984: if (call_user_function_ex(EG(function_table), NULL, *func, &retval_ptr, count, func_params, 0, NULL TSRMLS_CC) == SUCCESS ) { if (retval_ptr) { COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); } I compiled it and ran the test that Benjamin posted on the 16th of Augest. I did get the correct output (11, 17, & 23). The modified file is available from: http://www.domain51productions.com/php/basic_functions.c In the latest 5.0.X CVS, these lines have moved to 1991 - 1992. Note: If there's another way to handle submitting a patch, just let me know. -Travis