php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #33598 Throwing exception from __destruct causes fatal error
Submitted: 2005-07-07 01:46 UTC Modified: 2005-08-29 17:59 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:3 (100.0%)
From: carlo dot razzeto at mtginfo dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5CVS-2005-08-03 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
16 - 1 = ?
Subscribe to this entry?

 
 [2005-07-07 01:46 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-22 17:54 UTC] sniper@php.net
Throwing exceptions in __desctruct() is not allowed.
Should be documented..

 [2005-08-29 17:59 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"Attempting to throw an exception from a desctructor causes a fatal error."
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 22:01:30 2024 UTC