Bug #73337 [Opn->Csd]: try/catch not working with two exceptions inside a same operation
| From: | dmitry@php.net | Date: | Tue, 18 Oct 2016 12:10:57 +0000 |
| Subject: | Bug #73337 [Opn->Csd]: try/catch not working with two exceptions inside a same operation | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-204894@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73337&edit=1
ID: 73337
Updated by: dmitry@php.net
Reported by: bwoebi@php.net
Summary: try/catch not working with two exceptions inside a
same operation
-Status: Open
+Status: Closed
Type: Bug
Package: Scripting Engine problem
Operating System: Irrelevant
PHP Version: 7.1.0RC3
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=6558559bcc1cd24e3639e4a215e9d546ee05fc48
Log: Fixed bug #73337 (try/catch not working with two exceptions inside a same operation)
Previous Comments:
------------------------------------------------------------------------
[2016-10-18 10:27:02] bwoebi@php.net
Description:
------------
If two exceptions happen to be thrown inside a same opcode (the last one of both *must* be thrown
from within a separate function, e.g. an userland destructor).
The bug is in zend_throw_exception_internal(). We do not overwrite EG(opline_before_exception) in
case the current opcode is ZEND_HANDLE_EXCEPTION.
This is problematic in the case we aren't yet at that opcode, but it just got set to it by a
previous call to zend_throw_exception_internal(). I.e. in case one exception has been triggered and
then another exception is thrown within the same opcode.
This leads to throw_op_num (= EG(opline_before_exception) - EX(func)->op_array.opcodes) inside
ZEND_HANDLE_EXCEPTION opcode being bogus and catching does not work thus.
Test script:
---------------
class d { function __destruct() { throw new Error; } }
try { new d + new d; } catch (Error $e) { print "Exception properly caught"; }
Expected result:
----------------
Exception properly caught
Actual result:
--------------
Fatal error: Uncaught Error in Command line code:1
Stack trace:
#0 Command line code(1): d->__destruct()
#1 {main}
Next Error in Command line code:1
Stack trace:
#0 Command line code(1): d->__destruct()
#1 {main}
thrown in Command line code on line 1
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73337&edit=1