I am looking at Laravel code and found this in the Authenticate.php middleware:
public function handle($request, Closure $next, ...$guards)
{
$this->authenticate($guards);
return $next($request);
}
I have never seen such a thing, what do the 3 points do? I have googled it but found nothing
That's a spread operator... here's the relevant documentation: http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list
It essentially converts an array into a set of arguments, or converts a set of arguments into an array.
PHP has support for variable-length argument lists in user-defined functions. This is implemented using the ... token in PHP 5.6 and later, and using the func_num_args(), func_get_arg(), and func_get_args() functions in PHP 5.5 and earlier. Adding php.net link
http://php.net/manual/ro/functions.arguments.php#functions.variable-arg-list
function foo(...$params)
{
print_r($params);
}
foo('a','b');
Output
array('a','b');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With