函数参数前的三个点代表什么?
问题描述:
我正在使用Laravel 5.3,在其中一个功能中,我发现 代码:
I was working with Laravel 5.3 and in one of the functions, I found this piece of code:
public function handle($request, Closure $next, ...$guards)
{
$this->authenticate($guards);
return $next($request);
}
代码来自\Illuminate\Auth\Middleware\Authenticate::class
.
$guards
变量之前的那三个点是什么?
What are those 3 dots before $guards
variable?
答
它表示可能存在可变数量的参数.
It indicates that there may be a variable number of arguments.
当调用函数的参数超过3个时,$next
之后的所有参数都将添加到$guards
数组中.
When the function is called with more than 3 arguments, all the arguments after $next
will be added to the $guards
array.
您可以在此处上阅读有关内容.
You can read about it here.