Skip to content

Commit e9c0367

Browse files
committed
Fixed bug #77882
1 parent 1e7f1b9 commit e9c0367

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
@@ -26,6 +26,7 @@ PHP NEWS
2626

2727
- Reflection:
2828
. Fixed bug #77772 (ReflectionClass::getMethods(null) doesn't work). (Nikita)
29+
. Fixed bug #77882 (Different behavior: always calls destructor). (Nikita)
2930

3031
- Standard:
3132
. Fixed bug #77680 (recursive mkdir on ftp stream wrapper is incorrect).

ext/reflection/php_reflection.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4785,6 +4785,10 @@ ZEND_METHOD(reflection_class, newInstance)
47854785
for (i = 0; i < num_args; i++) {
47864786
zval_ptr_dtor(&params[i]);
47874787
}
4788+
4789+
if (EG(exception)) {
4790+
zend_object_store_ctor_failed(Z_OBJ_P(return_value));
4791+
}
47884792
if (ret == FAILURE) {
47894793
php_error_docref(NULL, E_WARNING, "Invocation of %s's constructor failed", ZSTR_VAL(ce->name));
47904794
zval_dtor(return_value);
@@ -4890,6 +4894,10 @@ ZEND_METHOD(reflection_class, newInstanceArgs)
48904894
}
48914895
efree(params);
48924896
}
4897+
4898+
if (EG(exception)) {
4899+
zend_object_store_ctor_failed(Z_OBJ_P(return_value));
4900+
}
48934901
if (ret == FAILURE) {
48944902
zval_ptr_dtor(&retval);
48954903
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)