函数参数前的三个点代表什么?

Sal*_*lar 17 php laravel

我正在使用Laravel 5.3并在其中一个函数中找到了这段代码:

public function handle($request, Closure $next, ...$guards)
{
    $this->authenticate($guards);

    return $next($request);
}
Run Code Online (Sandbox Code Playgroud)

代码来自\Illuminate\Auth\Middleware\Authenticate::class.

$guards变量之前的那3个点是什么?

小智 18

它表明可能存在可变数量的参数.

当使用3个以上的参数调用该函数时,之后的所有参数$next都将添加到$guards数组中.

你可以在这里阅读它.

  • 如果只发送 3 个参数,`$guards` 仍然是一个数组吗? (2认同)
  • 确认后,`$guards`仍将是一个数组,请点击[此处](https://repl.it/repls/LightgreenThornyWorkspaces)查看示例。 (2认同)