summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@php.net>2010-12-09 16:38:37 +0000
committerDmitry Stogov <dmitry@php.net>2010-12-09 16:38:37 +0000
commitc35fc7889025816f76d142b43a3a2452a59869d5 (patch)
tree0a1e904d8758fa9c3164c84b88f5b4a6c6cf4698
parentf69051602afb7db11214c43b6b401ac675c2d7db (diff)
downloadphp-git-c35fc7889025816f76d142b43a3a2452a59869d5.tar.gz
Fixed bug #53511 (Exceptions are lost in case an exception is thrown in catch operator)
-rw-r--r--Zend/tests/bug53511.phpt33
-rw-r--r--Zend/zend_vm_def.h2
-rw-r--r--Zend/zend_vm_execute.h2
-rwxr-xr-xext/spl/tests/iterator_041b.phpt13
4 files changed, 48 insertions, 2 deletions
diff --git a/Zend/tests/bug53511.phpt b/Zend/tests/bug53511.phpt
new file mode 100644
index 0000000000..88f0cbe8f4
--- /dev/null
+++ b/Zend/tests/bug53511.phpt
@@ -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
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index 005c92b532..bbb8052174 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -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;
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index b6a1179b25..42425d9cd6 100644
--- a/Zend/zend_vm_execute.h
+++ b/Zend/zend_vm_execute.h
@@ -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;
diff --git a/ext/spl/tests/iterator_041b.phpt b/ext/spl/tests/iterator_041b.phpt
index e166f6bdce..e7ea8b8008 100755
--- a/ext/spl/tests/iterator_041b.phpt
+++ b/ext/spl/tests/iterator_041b.phpt
@@ -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===