note 117693 added to language.oop5.decon
| From: | cottton | Date: | Thu, 23 Jul 2015 19:06:54 +0000 |
| Subject: | note 117693 added to language.oop5.decon | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203166@lists.php.net to get a copy of this message | ||
[quote]
Note:
Attempting to throw an exception from a destructor (called in the time of script termination) causes
a fatal error.
[/quote]
Not true.
Usually you wont be able to catch an Exception thrown out of a ::__destruct().
BUT following case shows that it IS possible to catch a thrown Exception from the ::__destruct()
<?php
class Something
{
public function __construct()
{
echo __METHOD__ . PHP_EOL;
}
public function __destruct()
{
echo __METHOD__ . PHP_EOL;
throw new Exception("Exception thrown out of ::__destruct()", 1);
}
}
try{
$Something = new Something();
$Something = null; // will cause to call the objects ::__destruct()
// also possible: unset($Something);
}catch(Exception $e){
echo 'Exception: ' . $e->getMessage() . PHP_EOL;
}
echo 'End of script -- no Fatal Error.';
?>
IMO this is not a bug. It is ok to be able to throw and catch Exception.
----
Server IP: 72.52.91.14
Probable Submitter: 178.24.94.13
----
Manual Page -- http://php.net/manual/en/language.oop5.decon.php
Edit -- https://master.php.net/note/edit/117693
Del: integrated -- https://master.php.net/note/delete/117693/integrated
Del: useless -- https://master.php.net/note/delete/117693/useless
Del: bad code -- https://master.php.net/note/delete/117693/bad+code
Del: spam -- https://master.php.net/note/delete/117693/spam
Del: non-english -- https://master.php.net/note/delete/117693/non-english
Del: in docs -- https://master.php.net/note/delete/117693/in+docs
Del: other reasons-- https://master.php.net/note/delete/117693
Reject -- https://master.php.net/note/reject/117693
Search -- https://master.php.net/manage/user-notes.php