26

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);
}

The code comes from \Illuminate\Auth\Middleware\Authenticate::class.

What are those 3 dots before $guards variable?

1

1 Answer 1

33

It indicates that there may be a variable number of arguments.

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Will $guards still be an array if a ONLY 3 parameters are sent?
Just noticed the last time the answerer was available (Dec 11 '16 at 19:52), if anyone else stumbling across can answer my above comment, please do so.
Confirmed, $guards will still be an array, please click here to see an example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.