#29368 [Com]: The destructor is called when an exception is thrown from the constructor
| From: | ernest at vogelsinger dot at | Date: | Fri, 24 Sep 2004 14:43:46 +0000 |
| Subject: | #29368 [Com]: The destructor is called when an exception is thrown from the constructor | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-66642@lists.php.net to get a copy of this message | ||
ID: 29368
Comment by: ernest at vogelsinger dot at
Reported By: fixxxer at php5 dot ru
Status: Closed
Bug Type: Zend Engine 2 problem
Operating System: *
PHP Version: 5.0.0
Assigned To: helly
New Comment:
This bug still (again?) exists in 5.0.2/Win32!
Previous Comments:
------------------------------------------------------------------------
[2004-07-25 19:39:06] helly@php.net
This bug has been fixed in CVS.
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.
------------------------------------------------------------------------
[2004-07-24 22:43:10] fixxxer at php5 dot ru
Description:
------------
The destructor is called if throwing an exception from the constructor.
This seems at least illogical and it's contrary to usual behaviour of
alike languages like C++ where destructor is not called in this case.
Reproduce code:
---------------
<?
class foo {
function __construct() {
echo "Inside constructor\n";
throw new Exception;
}
function __destruct() {
echo "Inside destructor\n";
}
}
try {
$bar = new foo;
} catch(Exception $exc) {
echo "Caught exception!\n";
}
?>
Expected result:
----------------
Inside constructor
Caught exception!
Actual result:
--------------
Inside constructor
Inside destructor
Caught exception!
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=29368&edit=1