diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-15 10:22:40 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-15 10:22:40 +0200 |
commit | e9c0367fdc4653331f398df36a10db1c54d6f3df (patch) | |
tree | 73d3425a069edc7b889e2798ce27ad6b1e754fd9 | |
parent | 1e7f1b90e8118aeece2dc48c5252d6979d2e0a3a (diff) | |
download | php-git-e9c0367fdc4653331f398df36a10db1c54d6f3df.tar.gz |
Fixed bug #77882
-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
@@ -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). diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 80e508c175..0a59d9a74c 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -4785,6 +4785,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_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 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 |