diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-15 10:25:00 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-15 10:25:11 +0200 |
commit | 14047b50b49c9dac55c5bac0404e3c844d33eeeb (patch) | |
tree | bcdf5432ef5daac090959e0d63a77374e007a821 | |
parent | 3e1eff251be4b1d24079fb3e74c7a62d9eccc771 (diff) | |
parent | e9c0367fdc4653331f398df36a10db1c54d6f3df (diff) | |
download | php-git-14047b50b49c9dac55c5bac0404e3c844d33eeeb.tar.gz |
Merge branch 'PHP-7.2' into PHP-7.3
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | ext/reflection/php_reflection.c | 8 | ||||
-rw-r--r-- | ext/reflection/tests/bug77882.phpt | 38 |
3 files changed, 47 insertions, 0 deletions
@@ -37,6 +37,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 #77793 (Segmentation fault in extract() when overwriting diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 2fa073cbea..f30f47f2b7 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -4720,6 +4720,10 @@ ZEND_METHOD(reflection_class, newInstance) for (i = 0; i < num_args; i++) { zval_ptr_dtor(¶ms[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_ptr_dtor(return_value); @@ -4820,6 +4824,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 index 0000000000..ff1d212861 --- /dev/null +++ b/ext/reflection/tests/bug77882.phpt @@ -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 |