Skip to content

Commit 13f75a0

Browse files
committed
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5: ext/reflection: Don't call destructor when constructor is not public in newInstance(Args)()
2 parents c41c722 + 18652e6 commit 13f75a0

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ PHP NEWS
182182
. Fixed ReflectionMethod::getClosure() returning a closure for abstract
183183
methods, which crashed when called for the ones of internal classes.
184184
(Nicolas Grekas)
185+
. Don't call destructor when constructor is not public in newInstance(Args)().
186+
(ndossche)
185187

186188
- Session:
187189
. Fixed session upload progress to respect session.use_only_cookies.

‎ext/reflection/php_reflection.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5001,6 +5001,7 @@ ZEND_METHOD(ReflectionClass, newInstance)
50015001
if (constructor) {
50025002
if (!(constructor->common.fn_flags & ZEND_ACC_PUBLIC)) {
50035003
zend_throw_exception_ex(reflection_exception_ptr, 0, "Access to non-public constructor of class %pS", ce->name);
5004+
zend_object_store_ctor_failed(Z_OBJ_P(return_value));
50045005
zval_ptr_dtor(return_value);
50055006
RETURN_NULL();
50065007
}
@@ -5076,6 +5077,7 @@ ZEND_METHOD(ReflectionClass, newInstanceArgs)
50765077
if (constructor) {
50775078
if (!(constructor->common.fn_flags & ZEND_ACC_PUBLIC)) {
50785079
zend_throw_exception_ex(reflection_exception_ptr, 0, "Access to non-public constructor of class %pS", ce->name);
5080+
zend_object_store_ctor_failed(Z_OBJ_P(return_value));
50795081
zval_ptr_dtor(return_value);
50805082
RETURN_NULL();
50815083
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
ReflectionClass::newInstance(Args)() must not call the destructor when the constructor is not public
3+
--FILE--
4+
<?php
5+
6+
class A {
7+
private function __construct() {}
8+
9+
public function __destruct() {
10+
echo "dtor\n";
11+
}
12+
}
13+
14+
$rc = new ReflectionClass(A::class);
15+
try {
16+
$rc->newInstance();
17+
} catch (Throwable $e) {
18+
echo $e::class, ": ", $e->getMessage(), "\n";
19+
}
20+
try {
21+
$rc->newInstanceArgs();
22+
} catch (Throwable $e) {
23+
echo $e::class, ": ", $e->getMessage(), "\n";
24+
}
25+
26+
?>
27+
--EXPECT--
28+
ReflectionException: Access to non-public constructor of class A
29+
ReflectionException: Access to non-public constructor of class A

0 commit comments

Comments
 (0)