$app = function ($request) { echo $request . " "; return "项目运行中....."; }; // 现在想在$app中加入一些额外的信息 $checkToken = function ($request, Closure $next) { echo "检测token中.... "; $response = $next($request); echo "检测token完成 "; return $response; }; $checkPermission = function ($request, Closure $next) { echo "检测权限中.... "; $response = $next($request); echo "检测权限完成 "; return $response; }; $middleware = [ $checkToken, $checkPermission ]; $next = $app; foreach ($middleware as $m) { $next = function ($request) use ($m, $next) { return $m($request, $next); }; } $res = $next("haha"); echo $res;