#33598 [Opn->Fbk]: Throwing exception from __destruct causes fatal error

From: Date: Thu, 07 Jul 2005 07:43:18 +0000
Subject: #33598 [Opn->Fbk]: Throwing exception from __destruct causes fatal error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-81517@lists.php.net to get a copy of this message
ID: 33598 Updated by: tony2001@php.net Reported By: carlo dot razzeto at mtginfo dot com -Status: Open +Status: Feedback Bug Type: Class/Object related Operating System: Linux version 2.4.21-27.0.2.ELsm PHP Version: 5.0.4 New Comment: Please try using this CVS snapshot: http://snaps.php.net/php5-latest.tar.gz For Windows: http://snaps.php.net/win32/php5-win32-latest.zip Previous Comments: ------------------------------------------------------------------------ [2005-07-07 01:46:59] carlo dot razzeto at mtginfo dot com 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 this bug report at http://bugs.php.net/?id=33598&edit=1

« previous php.bugs (#81517) next »