From 52969bcb7e8b07ad96ba402b87c441d8fde8b9a3 Mon Sep 17 00:00:00 2001 From: Blood <33853639+9007967@users.noreply.github.com> Date: Sun, 26 Oct 2025 12:20:19 +0800 Subject: [PATCH] Update Dispatch.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复在PHP8.5下异常报错 Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect PHP 8.1 及之后,PHP 引入了属性访问的新机制,反射访问私有属性不再需要通过 setAccessible(true) 开启,该方法的调用变得多余,因此在 PHP 8.5 中被正式弃用。 通过版本判断兼容版本低于PHP8.1的使用环境。 --- src/think/route/Dispatch.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/think/route/Dispatch.php b/src/think/route/Dispatch.php index bde9889725..2afdc55355 100644 --- a/src/think/route/Dispatch.php +++ b/src/think/route/Dispatch.php @@ -185,7 +185,9 @@ protected function registerControllerMiddleware($controller): void if ($class->hasProperty('middleware')) { $reflectionProperty = $class->getProperty('middleware'); - $reflectionProperty->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $reflectionProperty->setAccessible(true); + } $middlewares = $reflectionProperty->getValue($controller); $action = $this->request->action(true);