ID: 39706
User updated by: magic dot bitbucket at gmail dot com
Reported By: magic dot bitbucket at gmail dot com
-Status: Bogus
+Status: Open
Bug Type: Scripting Engine problem
Operating System: GNU/Linux - Slackware 11
PHP Version: 5.2.0
Assigned To: dmitry
New Comment:
Sorry for asking, probably this isn't the right place for
this discussion, but why is an uncaught exception a fatal
error?
Fatal errors usually only occur when running out of
memory, calling undefined methods, syntax errors ... ?
An uncaught exception IMHO doesn't really fit into this
category.
Since there is no way to enforce try blocks in PHP when
writing a library that someone else uses,
you can't guarantee the exception will be caught and thus
destructors are quite useless for resource cleanup (temp
files, transactions).
Sorry for reopening but I really don't understand the
rationale. And sorry for my english ^^
Previous Comments:
------------------------------------------------------------------------
[2006-12-04 13:47:20] [EMAIL PROTECTED]
PHP doesn't call destructors after fatal errors. The "Uncaught
exception" is an ordinary fatal error too, so the behavior is expected.
------------------------------------------------------------------------
[2006-12-01 16:34:36] magic dot bitbucket at gmail dot com
Description:
------------
When throwing an Exception and not catching it, Object destructors
don't get called.
I don't know if this is a bug or a feature, but surely it isn't
expected behaviour and it isn't documented.
This allows Objects to go out of scope without the destructor being
called and makes destructors useless as cleanup has to be done manually
before even thinking about throwing an Exception.
Reproduce code:
---------------
#!/usr/bin/php
<?php
class ExceptionTest {
public function __construct(){}
public function __destruct() { echo "hilfe mein leben!\n"; }
}
$test=new ExceptionTest();
throw new Exception('why are the destructors not called?', 666);
?>
Expected result:
----------------
I would expect __destruct() to be called when throwing the Exception.
Actual result:
--------------
__destruct() isn't called.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=39706&edit=1