From e9c0367fdc4653331f398df36a10db1c54d6f3df Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 15 Apr 2019 10:22:40 +0200 Subject: Fixed bug #77882 --- NEWS | 1 + ext/reflection/php_reflection.c | 8 ++++++++ ext/reflection/tests/bug77882.phpt | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 ext/reflection/tests/bug77882.phpt diff --git a/NEWS b/NEWS index 10f154298f..7c395f5208 100644 --- 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). 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-- +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 -- cgit v1.2.1