]> granicus.if.org Git - php/commitdiff
Fixed bug #53511 (Exceptions are lost in case an exception is thrown in catch operator)
authorDmitry Stogov <dmitry@php.net>
Thu, 9 Dec 2010 16:38:37 +0000 (16:38 +0000)
committerDmitry Stogov <dmitry@php.net>
Thu, 9 Dec 2010 16:38:37 +0000 (16:38 +0000)
Zend/tests/bug53511.phpt [new file with mode: 0644]
Zend/zend_vm_def.h
Zend/zend_vm_execute.h
ext/spl/tests/iterator_041b.phpt

diff --git a/Zend/tests/bug53511.phpt b/Zend/tests/bug53511.phpt
new file mode 100644 (file)
index 0000000..88f0cbe
--- /dev/null
@@ -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
index 005c92b53278f6d013b654899d3ad9440dd2d240..bbb80521744b967244b5b49ed9aaead65ecc0f72 100644 (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;
index b6a1179b25d105619514483b74a7405c42f9651b..42425d9cd695bf602c1a97c2e593c6ba155e091d 100644 (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;
index e166f6bdce2dc11ef811fa572f6a310006158091..e7ea8b800824f9a0561f4b6b9523049943add96f 100755 (executable)
@@ -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===