#33598 [NEW]: Throwing exception from __destruct causes fatal error
| From: | carlo dot razzeto at mtginfo dot com | Date: | Wed, 06 Jul 2005 23:47:00 +0000 |
| Subject: | #33598 [NEW]: Throwing exception from __destruct causes fatal error | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-81503@lists.php.net to get a copy of this message | ||
From: carlo dot razzeto at mtginfo dot com
Operating system: Linux version 2.4.21-27.0.2.ELsm
PHP version: 5.0.4
PHP Bug Type: Class/Object related
Bug description: Throwing exception from __destruct causes fatal error
Description:
------------
When performing an operation which throws an exception in the __destruct
method of a class, the following Error is generated
Fatal error: Exception thrown without a stack frame in Unknown on line 0
I have only observed this happening when an object goes out of scope
because the script has ended. Rather than generating a scripting engine
error, PHP should allow for the script to deal with the error, for
instance when an exception handler has been specified by the script.
Reproduce code:
---------------
class test {
function __construct() {
echo "Construct\n";
}
function greet() {
echo "Hello World\n";
}
function __destruct() {
echo "Destruct\n";
throw new Exception( 'test' );
}
}
$test = new test();
$test->greet();
Expected result:
----------------
Construct
Hello World
Destruct
Fatal error: Uncaught exception 'Exception' with message 'test' in
/home/crazzeto/test.php:13
Stack trace:
#0 /home/crazzeto/test.php(13): test::__destruct()
#1 /home/crazzeto/test.php(20): test::__destruct()
#2 /home/crazzeto/test.php(20): unknown()
#3 {main}
thrown in /home/crazzeto/test.php on line 13
Actual result:
--------------
[crazzeto@DEVEL crazzeto]$ php test.php
Construct
Hello World
Destruct
Fatal error: Exception thrown without a stack frame in Unknown on line 0
--
Edit bug report at http://bugs.php.net/?id=33598&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33598&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=33598&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=33598&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=33598&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=33598&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=33598&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=33598&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=33598&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=33598&r=support
Expected behavior: http://bugs.php.net/fix.php?id=33598&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=33598&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=33598&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=33598&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33598&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=33598&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=33598&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=33598&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=33598&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=33598&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=33598&r=mysqlcfg