1 September 2016

laravel error: unexpected . at line 475 in Illuminate/Foundation/helpers.php

Laravel header Whilst I was setting up a Laravel 5.3 site recently, I encountered the following error when the site was deployed on the server:

Unexpected . at line 475 in Illuminate/Foundation/helpers.php

Looking at the source of the error I could quickly see the problem:


function event(...$args)
    return app('events')->fire(...$args);

The event function is a variadic function, which means it takes a variable number of arguments.

The three dot notation used here in the function definition was introduced in PHP 5.6. (Prior to this you would have to use func_num_args(), func_get_arg(), and func_get_args() to achieve the same thing.

The version of PHP installed on the server was 5.5.x, which does not have this feature. Also, the 5.5 branch of PHP is no longer supported, so an upgrade should be taken care of as soon as possible.

A quick upgrade to PHP 7.0 solved my problem and Laravel immediately worked as intended. I could have installed 5.6, but seeing as the 5.6 branch reaches it's end-of-life on the 1st of January 2017 I decided to go straight to 7.0.

Hopefully this will help if anyone else encounters this problem.

Post a comment



(required, not published)