Skip to content

Commit 14047b5

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
2 parents 3e1eff2 + e9c0367 commit 14047b5

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ PHP NEWS
3737

3838
- Reflection:
3939
. Fixed bug #77772 (ReflectionClass::getMethods(null) doesn't work). (Nikita)
40+
. Fixed bug #77882 (Different behavior: always calls destructor). (Nikita)
4041

4142
- Standard:
4243
. Fixed bug #77793 (Segmentation fault in extract() when overwriting

ext/reflection/php_reflection.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4720,6 +4720,10 @@ ZEND_METHOD(reflection_class, newInstance)
47204720
for (i = 0; i < num_args; i++) {
47214721
zval_ptr_dtor(&params[i]);
47224722
}
4723+
4724+
if (EG(exception)) {
4725+
zend_object_store_ctor_failed(Z_OBJ_P(return_value));
4726+
}
47234727
if (ret == FAILURE) {
47244728
php_error_docref(NULL, E_WARNING, "Invocation of %s's constructor failed", ZSTR_VAL(ce->name));
47254729
zval_ptr_dtor(return_value);
@@ -4820,6 +4824,10 @@ ZEND_METHOD(reflection_class, newInstanceArgs)
48204824
}
48214825
efree(params);
48224826
}
4827+
4828+
if (EG(exception)) {
4829+
zend_object_store_ctor_failed(Z_OBJ_P(return_value));
4830+
}
48234831
if (ret == FAILURE) {
48244832
zval_ptr_dtor(&retval);
48254833
php_error_docref(NULL, E_WARNING, "Invocation of %s's constructor failed", ZSTR_VAL(ce->name));

ext/reflection/tests/bug77882.phpt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
Bug #77882: Different behavior: always calls destructor
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public function __construct() {
8+
throw new Exception();
9+
}
10+
11+
public function __destruct() {
12+
echo "__destruct\n";
13+
}
14+
}
15+
16+
try {
17+
new Test();
18+
} catch (Exception $e) {
19+
echo "Exception\n";
20+
}
21+
try {
22+
$ref = new ReflectionClass('Test');
23+
$obj = $ref->newInstance();
24+
} catch (Exception $e) {
25+
echo "Exception\n";
26+
}
27+
try {
28+
$ref = new ReflectionClass('Test');
29+
$obj = $ref->newInstanceArgs([]);
30+
} catch (Exception $e) {
31+
echo "Exception\n";
32+
}
33+
34+
?>
35+
--EXPECT--
36+
Exception
37+
Exception
38+
Exception

0 commit comments

Comments
 (0)