Fixed bug #53511 (Exceptions are lost in case an exception is thrown in catch operator)

This commit is contained in:
Dmitry Stogov 2010-12-09 16:38:37 +00:00
parent f69051602a
commit c35fc78890
4 changed files with 48 additions and 2 deletions

33
Zend/tests/bug53511.phpt Normal file
View File

@ -0,0 +1,33 @@
--TEST--
Bug #53511 (Exceptions are lost in case an exception is thrown in catch operator)
--FILE--
<?php
class Foo {
function __destruct() {
throw new Exception("ops 1");
}
}
function test() {
$e = new Foo();
try {
throw new Exception("ops 2");
} catch (Exception $e) {
echo $e->getMessage()."\n";
}
}
test();
echo "bug\n";
--EXPECTF--
Fatal error: Uncaught exception 'Exception' with message 'ops 2' in %sbug53511.php:11
Stack trace:
#0 %sbug53511.php(17): test()
#1 {main}
Next exception 'Exception' with message 'ops 1' in %sbug53511.php:4
Stack trace:
#0 %sbug53511.php(12): Foo->__destruct()
#1 %sbug53511.php(17): test()
#2 {main}
thrown in %sbug53511.php on line 4

View File

@ -2918,7 +2918,7 @@ ZEND_VM_HANDLER(107, ZEND_CATCH, CONST, CV)
&EG(exception), sizeof(zval *), (void**)&EX_CV(opline->op2.var));
}
if (UNEXPECTED(EG(exception) != exception)) {
EG(exception) = NULL;
Z_ADDREF_P(EG(exception));
HANDLE_EXCEPTION();
} else {
EG(exception) = NULL;

View File

@ -5843,7 +5843,7 @@ static int ZEND_FASTCALL ZEND_CATCH_SPEC_CONST_CV_HANDLER(ZEND_OPCODE_HANDLER_A
&EG(exception), sizeof(zval *), (void**)&EX_CV(opline->op2.var));
}
if (UNEXPECTED(EG(exception) != exception)) {
EG(exception) = NULL;
Z_ADDREF_P(EG(exception));
HANDLE_EXCEPTION();
} else {
EG(exception) = NULL;

View File

@ -82,6 +82,10 @@ class MyArrayIterator extends ArrayIterator
{
self::$fail++;
}
try {
$e = null;
} catch (Exception $e) {
}
}
}
}
@ -101,10 +105,19 @@ State 3: valid()
State 4: current()
State 5: key()
State 6: next()
State 7: __destruct()
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
===iterator_count===
State 0: __construct()
State 1: __construct()
State 2: rewind()
State 3: valid()
State 6: next()
State 7: __destruct()
int(2)
===DONE===