php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29617 call_user_func_array doesn't handle correctly Exceptions
Submitted: 2004-08-11 16:58 UTC Modified: 2004-08-19 06:53 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (33.3%)
From: jpbarrette at savoirfairelinux dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.0 OS: Mandrake linux 10.0 (Community)
Private report: No CVE-ID: None
 [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:
----------------
 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-11 17:23 UTC] derick@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try avoid embedding huge scripts into the report.
 [2004-08-11 17:26 UTC] jpbarrette at savoirfairelinux dot net
The fixed code: 
 
<?php 
 
function test($test) { 
  throw new Exception("This is a " . $test); 
} 
 
call_user_func_array("test", array("test")); 
 
?>
 [2004-08-16 06:42 UTC] php dot net at benjamin dot schulz dot name
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
23
 [2004-08-16 06:44 UTC] php dot net at benjamin dot schulz dot name
this is 5.0.1 here
 [2004-08-19 01:34 UTC] JustinHagstrom at yahoo dot com
This bug was already reported here: http://bugs.php.net/bug.php?id=28934
 [2004-08-19 06:53 UTC] tony2001@php.net
Duplicate of #28934.
 [2004-09-10 18:56 UTC] php at d51 dot biz
I'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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 07 06:01:30 2024 UTC