]> granicus.if.org Git - php/commitdiff
Fixed bug #77882
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 15 Apr 2019 08:22:40 +0000 (10:22 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 15 Apr 2019 08:22:40 +0000 (10:22 +0200)
NEWS
ext/reflection/php_reflection.c
ext/reflection/tests/bug77882.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 10f154298f2b3df90c7044b4862144ec2ea8b2be..7c395f520897d8dc71c27956f0c020c82f38473d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,7 @@ PHP                                                                        NEWS
     
 - Reflection:
   . Fixed bug #77772 (ReflectionClass::getMethods(null) doesn't work). (Nikita)
+  . Fixed bug #77882 (Different behavior: always calls destructor). (Nikita)
 
 - Standard:
   . Fixed bug #77680 (recursive mkdir on ftp stream wrapper is incorrect).
index 80e508c1750b214a525d015c2925de1cced1302b..0a59d9a74c678a369ace90ad834518208eca827e 100644 (file)
@@ -4785,6 +4785,10 @@ ZEND_METHOD(reflection_class, newInstance)
                for (i = 0; i < num_args; i++) {
                        zval_ptr_dtor(&params[i]);
                }
+
+               if (EG(exception)) {
+                       zend_object_store_ctor_failed(Z_OBJ_P(return_value));
+               }
                if (ret == FAILURE) {
                        php_error_docref(NULL, E_WARNING, "Invocation of %s's constructor failed", ZSTR_VAL(ce->name));
                        zval_dtor(return_value);
@@ -4890,6 +4894,10 @@ ZEND_METHOD(reflection_class, newInstanceArgs)
                        }
                        efree(params);
                }
+
+               if (EG(exception)) {
+                       zend_object_store_ctor_failed(Z_OBJ_P(return_value));
+               }
                if (ret == FAILURE) {
                        zval_ptr_dtor(&retval);
                        php_error_docref(NULL, E_WARNING, "Invocation of %s's constructor failed", ZSTR_VAL(ce->name));
diff --git a/ext/reflection/tests/bug77882.phpt b/ext/reflection/tests/bug77882.phpt
new file mode 100644 (file)
index 0000000..ff1d212
--- /dev/null
@@ -0,0 +1,38 @@
+--TEST--
+Bug #77882: Different behavior: always calls destructor
+--FILE--
+<?php
+
+class Test {
+    public function __construct() {
+        throw new Exception();
+    }
+    
+    public function __destruct() {
+        echo "__destruct\n";
+    }
+}
+
+try {
+    new Test();
+} catch (Exception $e) {
+    echo "Exception\n";
+}
+try {
+    $ref = new ReflectionClass('Test');
+    $obj = $ref->newInstance();
+} catch (Exception $e) {
+    echo "Exception\n";
+}
+try {
+    $ref = new ReflectionClass('Test');
+    $obj = $ref->newInstanceArgs([]);
+} catch (Exception $e) {
+    echo "Exception\n";
+}
+
+?>
+--EXPECT--
+Exception
+Exception
+Exception