[php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6
| From: | Daniel Scherzer | Date: | Tue, 17 Nov 2026 18:48:10 +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-143777@lists.php.net to get a copy of this message | ||
Author: Daniel Scherzer (DanielEScherzer)
Date: 2026-11-17T10:45:54-08:00
Commit: https://github.com/php/php-src/commit/cfb02068f907af3e7bec24d43e4b5a185abdbba8
Raw diff: https://github.com/php/php-src/commit/cfb02068f907af3e7bec24d43e4b5a185abdbba8.diff
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
Fix ReflectionMethod::getClosure() on abstract methods (#25494)
Changed paths:
A ext/reflection/tests/ReflectionMethod_getClosure_abstract.phpt
M NEWS
M ext/reflection/php_reflection.c
Diff:
diff --git a/NEWS b/NEWS
index 9b52776e7b01..d4c0610f9780 100644
--- a/NEWS
+++ b/NEWS
@@ -142,6 +142,9 @@ PHP NEWS
(ndossche)
. Fix ReflectionProperty::isReadable() not working for indirect slots.
(ndossche)
+ . Fixed ReflectionMethod::getClosure() returning a closure for abstract
+ methods, which crashed when called for the ones of internal classes.
+ (Nicolas Grekas)
- 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 ee93160d5a5e..c142c78449dc 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -3321,6 +3321,13 @@ ZEND_METHOD(ReflectionMethod, getClosure)
GET_REFLECTION_OBJECT_PTR(mptr);
+ if (mptr->common.fn_flags & ZEND_ACC_ABSTRACT) {
+ zend_throw_exception_ex(reflection_exception_ptr, 0,
+ "Trying to create a closure from abstract method %s::%s()",
+ ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name));
+ RETURN_THROWS();
+ }
+
if (mptr->common.fn_flags & ZEND_ACC_STATIC) {
zend_create_fake_closure(return_value, mptr, mptr->common.scope, mptr->common.scope, NULL);
return;
diff --git a/ext/reflection/tests/ReflectionMethod_getClosure_abstract.phpt
b/ext/reflection/tests/ReflectionMethod_getClosure_abstract.phpt
new file mode 100644
index 000000000000..4f2ef9a8a715
--- /dev/null
+++ b/ext/reflection/tests/ReflectionMethod_getClosure_abstract.phpt
@@ -0,0 +1,37 @@
+--TEST--
+ReflectionMethod::getClosure() on abstract methods
+--FILE--
+<?php
+
+abstract class A {
+ abstract public function instance();
+ abstract public static function make();
+}
+
+class B extends A implements Countable {
+ public function instance() {}
+ public static function make() {}
+ public function count(): int { return 0; }
+}
+
+$methods = [
+ [new ReflectionMethod(A::class, 'instance'), new B()],
+ [new ReflectionMethod(A::class, 'make'), null],
+ [new ReflectionMethod(Countable::class, 'count'), new B()],
+ [new ReflectionMethod(UnitEnum::class, 'cases'), null],
+];
+
+foreach ($methods as [$method, $object]) {
+ try {
+ $method->getClosure($object);
+ } catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), "\n";
+ }
+}
+
+?>
+--EXPECT--
+ReflectionException: Trying to create a closure from abstract method A::instance()
+ReflectionException: Trying to create a closure from abstract method A::make()
+ReflectionException: Trying to create a closure from abstract method Countable::count()
+ReflectionException: Trying to create a closure from abstract method UnitEnum::cases()