|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #47143 Throwing an exception in a destructor causes a fatal error
Submitted: 2009-01-18 05:16 UTC Modified: 2011-01-16 22:26 UTC
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:1 (33.3%)
From: felixcca at yahoo dot ca Assigned: stas (profile)
Status: Closed Package: *General Issues
PHP Version: 5.2.8 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: felixcca at yahoo dot ca
New email:
PHP Version: OS:


 [2009-01-18 05:16 UTC] felixcca at yahoo dot ca
Basically a duplicate of #31304, but it seems I can't reopen the ticket 
myself since I'm not a dev nor the original poster.

When an exception is thrown in a destructor, the exception is lost, and 
a pointless Fatal Error is issued:
Fatal Error: Exception thrown without a stack trace

debug_backtrace() will still get you a stack trace from a destructor 
without issuing any error, let alone causing the loss of debugging data. 
Also, only wrapping the exception in a try-catch inside the destructor 
works, and allows you to just print the exception and exit as if 
exceptions really worked in destructors.

Why spit out the Fatal Error?

Reproduce code:
class ExceptionThrower
	public function __destruct()
		throw new Exception;
$obj = new ExceptionThrower;

Expected result:
Fatal error: Uncaught exception 'Exception' in snippet.php:6
Stack trace:
#0 [internal function]: ExceptionThrower->__destruct()
#1 {main}
  thrown in snippet.php on line 6

Actual result:
Fatal error: Exception thrown without a stack frame in Unknown on line 0


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-18 08:26 UTC] felixcca at yahoo dot ca
Sorry, made a mistake on the original error message. It's "Exception 
thrown without a stack frame," as stated below, and not "Exception 
thrown without a stack trace".
 [2011-01-16 22:24 UTC]
Automatic comment from SVN on behalf of stas
Log: Fix bug #47143, bug #51458 - provide more useful info in bad exception cases
 [2011-01-16 22:26 UTC]
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: stas
 [2011-01-16 22:26 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

 [2011-05-17 07:54 UTC] paul at annesley dot cc
More specifically, this was fixed between PHP 5.3.5 and PHP 5.3.6 in the following 

r307523 | stas | 2011-01-17 08:24:43 +1100 (Mon, 17 Jan 2011) | 2 lines
Fix bug #47143, bug #51458 - provide more useful info in bad exception cases

It didn't seem to make it into the ChangeLog, though.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Mar 26 07:05:48 2023 UTC