framework icon indicating copy to clipboard operation
framework copied to clipboard

路由中间件,使用数组方式传参,再进行 withoutMiddleware 排除中间件 异常

Open Dummercn opened this issue 11 months ago • 3 comments

所属功能组件

路由(Route)

ThinkPHP 版本

8.1

操作系统

macos

错误信息

如果在路由中间件中,使用数组方式传参,再进行 withoutMiddleware 排除中间件时 报错,如图片

Image Image Image Image

其它说明

No response

Dummercn avatar Jan 26 '25 05:01 Dummercn

1月26日的BUG,现在还没解决,官方不维护了么? 文件【vendor/topthink/framework/src/think/route/Dispatch.php】97行改为:$middleware = !empty($option['without_middleware']) ? array_diff(array_map(fn($item) => $item[0], $option['middleware']), $option['without_middleware']) : [];

qiyo avatar Jun 06 '25 04:06 qiyo

确实是有问题,在$option['middleware']列表出现数组的时候,array_diff的时候报错Array to string conversion

runphp avatar Oct 09 '25 09:10 runphp

$middleware = !empty($option['without_middleware']) ? array_diff(array_map(fn($item) => $item[0], $option['middleware']), $option['without_middleware']) : [];

这样改还是有个问题,如果中间件是闭包的情况,会报错误Object of class Closure could not be converted to string

runphp avatar Oct 09 '25 09:10 runphp