ID:               29617
 Comment by:       php at d51 dot biz
 Reported By:      jpbarrette at savoirfairelinux dot net
 Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: Mandrake linux 10.0 (Community)
 PHP Version:      5.0.0
 New Comment:

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


Previous Comments:
------------------------------------------------------------------------

[2004-08-19 06:53:32] [EMAIL PROTECTED]

Duplicate of #28934.

------------------------------------------------------------------------

[2004-08-19 01:34:28] JustinHagstrom at yahoo dot com

This bug was already reported here:
http://bugs.php.net/bug.php?id=28934

------------------------------------------------------------------------

[2004-08-16 06:44:25] php dot net at benjamin dot schulz dot name

this is 5.0.1 here

------------------------------------------------------------------------

[2004-08-16 06:42:46] 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-11 17:26:48] 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")); 
 
?>

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/29617

-- 
Edit this bug report at http://bugs.php.net/?id=29617&edit=1

Reply via email to