Edit report at http://bugs.php.net/bug.php?id=52361&edit=1
ID: 52361 Updated by: dmi...@php.net Reported by: hj dot devs at gmail dot com Summary: Throwing an exception in a destructor causes invalid catching -Status: Assigned +Status: Closed Type: Bug Package: Scripting Engine problem Operating System: Linux/Windows PHP Version: 5.3.2 Assigned To: dmitry Block user comment: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2010-08-16 11:20:48] dmi...@php.net Automatic comment from SVN on behalf of dmitry Revision: http://svn.php.net/viewvc/?view=revision&revision=302323 Log: Bug #52361 (Throwing an exception in a destructor causes invalid catching) ------------------------------------------------------------------------ [2010-08-16 10:11:10] dmi...@php.net Automatic comment from SVN on behalf of dmitry Revision: http://svn.php.net/viewvc/?view=revision&revision=302311 Log: Fixed memory leaks (related to bug #52361) ------------------------------------------------------------------------ [2010-07-16 14:12:14] 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-07-16 14:10:05] 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 !!! ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52361&edit=1