diff options
| author | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-15 10:25:20 +0200 |
|---|---|---|
| committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-15 10:25:20 +0200 |
| commit | b2ec07e64c7a05a21da0f88acce62592becda87e (patch) | |
| tree | 7ed5d331c547e57cf8b1952373b444d0f2b4a3a9 | |
| parent | f31435b8550d7d3291e1c1ca14c2aaeab5d5b915 (diff) | |
| parent | 14047b50b49c9dac55c5bac0404e3c844d33eeeb (diff) | |
| download | php-git-b2ec07e64c7a05a21da0f88acce62592becda87e.tar.gz | |
Merge branch 'PHP-7.3' into PHP-7.4
| -rw-r--r-- | ext/reflection/php_reflection.c | 8 | ||||
| -rw-r--r-- | ext/reflection/tests/bug77882.phpt | 38 |
2 files changed, 46 insertions, 0 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 5f8faa39b7..3fbe78d382 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -4682,6 +4682,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); @@ -4782,6 +4786,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 |
