php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52361 Throwing an exception in a destructor causes invalid catching
Submitted: 2010-07-16 14:10 UTC Modified: 2010-08-16 11:24 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: hj dot devs at gmail dot com Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.2 OS: Linux/Windows
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: hj dot devs at gmail dot com
New email:
PHP Version: OS:

 

 [2010-07-16 14:10 UTC] hj dot devs at gmail dot com
Description:
------------
When exceptions are thrown in destructor, PHP5.3.x does not catch any exceptions 
in caller's "try" block.
In addition, destructor's "try" block catches exceptions of caller.

Probably this behavior is bug because it works correctly on PHP5.2.13.

Test script:
---------------
<?php
class aaa {
	public function __destruct() {
		try {
			throw new Exception(__CLASS__);
		} catch(Exception $ex) {
		}
	}
}
function bbb() {
	$a = new aaa();
	throw new Exception(__FUNCTION__);
}
try {
	bbb();
	echo "must be skipped !!!";
} catch(Exception $ex) {
	echo $ex;
}

Expected result:
----------------
exception 'Exception' with message 'aaa' in example.php:5
Stack trace:
#0 example.php(16): aaa->__destruct()
#1 example.php(16): bbb()
#2 {main}
exception 'Exception' with message 'bbb' in example.php:13
Stack trace:
#0 example.php(16): bbb()
#1 {main}

Actual result:
--------------
exception 'Exception' with message 'bbb' in example.php:13
Stack trace:
#0 example.php(16): bbb()
#1 {main}

Next exception 'Exception' with message 'aaa' in example.php:5
Stack trace:
#0 example.php(16): aaa->__destruct()
#1 example.php(16): bbb()
#2 {main}
must be skipped !!!

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-16 14:12 UTC] hj dot devs at gmail dot com
I'm sorry, correct script is below.
-----------
<?php
class aaa {
	public function __destruct() {
		try {
			throw new Exception(__CLASS__);
		} catch(Exception $ex) {
			echo "$ex\n";
		}
	}
}
function bbb() {
	$a = new aaa();
	throw new Exception(__FUNCTION__);
}
try {
	bbb();
	echo "must be skipped !!!";
} catch(Exception $ex) {
	echo $ex;
}
 [2010-08-14 20:45 UTC] Felipe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: dmitry
 [2010-08-16 10:11 UTC] dmitry@php.net
Automatic comment from SVN on behalf of dmitry
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=302311
Log: Fixed memory leaks (related to bug #52361)
 [2010-08-16 11:20 UTC] dmitry@php.net
Automatic comment from SVN on behalf of dmitry
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=302323
Log: Bug #52361 (Throwing an exception in a destructor causes invalid catching)
 [2010-08-16 11:24 UTC] dmitry@php.net
-Status: Assigned +Status: Closed
 [2010-08-16 11:24 UTC] dmitry@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 10:01:29 2024 UTC