[php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6
| From: | ndossche | Date: | Mon, 23 Nov 2026 21:00:43 +0000 |
| Subject: | [php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-144083@lists.php.net to get a copy of this message | ||
Author: ndossche (ndossche)
Date: 2026-11-23T22:00:16+01:00
Commit: https://github.com/php/php-src/commit/13f75a02aaa04fb82cfec4c3560dbb0f94b4e99c
Raw diff: https://github.com/php/php-src/commit/13f75a02aaa04fb82cfec4c3560dbb0f94b4e99c.diff
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)()
Changed paths:
A ext/reflection/tests/newInstance_nonpublic_ctor_no_dtor.phpt
M NEWS
M ext/reflection/php_reflection.c
Diff:
diff --git a/NEWS b/NEWS
index 41b530a58cfb..5975696d9307 100644
--- a/NEWS
+++ b/NEWS
@@ -182,6 +182,8 @@ PHP NEWS
. Fixed ReflectionMethod::getClosure() returning a closure for abstract
methods, which crashed when called for the ones of internal classes.
(Nicolas Grekas)
+ . Don't call destructor when constructor is not public in newInstance(Args)().
+ (ndossche)
- Session:
. Fixed session upload progress to respect session.use_only_cookies.
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index 912be937a4be..618be5a40f66 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -5001,6 +5001,7 @@ ZEND_METHOD(ReflectionClass, newInstance)
if (constructor) {
if (!(constructor->common.fn_flags & ZEND_ACC_PUBLIC)) {
zend_throw_exception_ex(reflection_exception_ptr, 0, "Access to non-public constructor of
class %pS", ce->name);
+ zend_object_store_ctor_failed(Z_OBJ_P(return_value));
zval_ptr_dtor(return_value);
RETURN_NULL();
}
@@ -5076,6 +5077,7 @@ ZEND_METHOD(ReflectionClass, newInstanceArgs)
if (constructor) {
if (!(constructor->common.fn_flags & ZEND_ACC_PUBLIC)) {
zend_throw_exception_ex(reflection_exception_ptr, 0, "Access to non-public constructor of
class %pS", ce->name);
+ zend_object_store_ctor_failed(Z_OBJ_P(return_value));
zval_ptr_dtor(return_value);
RETURN_NULL();
}
diff --git a/ext/reflection/tests/newInstance_nonpublic_ctor_no_dtor.phpt
b/ext/reflection/tests/newInstance_nonpublic_ctor_no_dtor.phpt
new file mode 100644
index 000000000000..43940d8dea0a
--- /dev/null
+++ b/ext/reflection/tests/newInstance_nonpublic_ctor_no_dtor.phpt
@@ -0,0 +1,29 @@
+--TEST--
+ReflectionClass::newInstance(Args)() must not call the destructor when the constructor is not
public
+--FILE--
+<?php
+
+class A {
+ private function __construct() {}
+
+ public function __destruct() {
+ echo "dtor\n";
+ }
+}
+
+$rc = new ReflectionClass(A::class);
+try {
+ $rc->newInstance();
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), "\n";
+}
+try {
+ $rc->newInstanceArgs();
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+ReflectionException: Access to non-public constructor of class A
+ReflectionException: Access to non-public constructor of class A