ID:               25038
 Comment by:       jonny at sanriowasteland dot net
 Reported By:      tater at potatoe dot com
 Status:           Open
 Bug Type:         Zend Engine 2 problem
 Operating System: *
 PHP Version:      5CVS-2003-08-11 (dev)
 New Comment:

I've done some more testing with this.

>From waht I can tell (as a php programmer) the callstack is being
hosed.  Here is an example to show this:

The Code:
----------
<?php
function bar($x='no argument')
{
    throw new Exception("This is an exception from bar({$x}).");
}
try { bar('first try'); }
catch (Exception $e) { print $e->getmessage()."\n"; }

set_error_handler('handleError');

try { call_user_func('bar','second try'); }
catch (Exception $e) { print $e->getmessage()."\n"; }

function handleError($errno, $errstr, $errfile, $errline)
{
        echo "Have an error: $errno, $errstr, $errfile, $errline...\n";

        echo "Going to a function...";
        goInFunction(); 
        echo "Returned.\n";

        $t = debug_backtrace(); 
        var_dump($t);
}

function goInFunction()
{
        echo "In function...";
}
?>

Expected Result:
----------------
Nothing has changed from the previous bug, it should still be the same.
 However, if call_user_func('bar','second try'); is still supposed to
throw an error, this is what I expect:

This is an exception from bar(first try).
Have an error: 2, call_user_func(bar): Unable to call bar(second try),
php5Breakage2.php, 11...
Going to a function...In function...Returned
[insert a backtrace here]
This is an exception from bar(second try).

Actual Result:
--------------
This is an exception from bar(first try).
Have an error: 2, call_user_func(bar): Unable to call bar(second try),
php5Breakage2.php, 11...
Going to a function...In function...This is an exception from
bar(second try).

Note that if I comment out lines 18-20 (the call of the user function),
I would get:

This is an exception from bar(first try).
Have an error: 2, call_user_func(bar): Unable to call bar(second try),
php5Breakage2.php, 11...
This is an exception from bar(second try).

So it appears that both user function calls, and internal function
calls within the error handler mess up the stack.


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

[2003-10-08 07:59:46] rep at devdomain dot com

same here with call_user_func_array:

call_user_func_array fails when the method throws an exception issuing
a php warning, and the exception is lost in the process.

try {
  $mValue = call_user_func_array ($func, $params);
  // func throws exception, php warning issued

} catch (devException $oExc) {
  // never gets here
}

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

[2003-08-11 06:35:02] tater at potatoe dot com

Description:
------------
Throwing an exception from a function called by call_user_func() causes
a warning to be issued,
saying it was unable to call the function.

An odd side note: if I set up my own error handler,
it does not receive this warning. Kind of an 
inadvertant workaround for now...

Reproduce code:
---------------
function bar($x='no argument')
{
    throw new Exception("This is an exception from bar({$x}).");
}
try { bar('first try'); }
catch (Exception $e) { print "{$e->message}\n"; }
try { call_user_func('bar','second try'); }
catch (Exception $e) { print "{$e->message}\n"; }

Expected result:
----------------
This is an exception from bar(first try).
This is an exception from bar(second try).


Actual result:
--------------
This is an exception from bar(first try).

Warning: call_user_func(bar): Unable to call bar(second try) in
/my/pathname/test.php on line 8 
This is an exception from bar(second try).


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


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

Reply via email to