500 error on Fast Route when using shared hosting

When moving my Slim Framework set-up from local to a shared hosting, it throws a 500 error on all the routes.

The error details show:

Parse error: syntax error, unexpected '['
vendor/nikic/fast-route/src/functions.php on line 12

Line 12 is:
function simpleDispatcher(callable $routeDefinitionCallback, array $options = []) {

The issue is, it works fine locally, but not on this shared host, and I cannot work out why. Changing PHP version makes no difference.

Anyone can help?

I just had a similar problem yesterday. In my case I had a path issue on an include once. I don’t fully understand why it works on my local server and not my hosted server.

My project look something like this on my local machine:

lots/of/folders/root/slim/app.php lots/of/folders/root/mysql/helperphp

In the app.php I had:

include_once '/mysql/helper.php';

Which worked locally but not on the server. To get it to work on the server I changed the line to:

include_once __ DIR __ . ‘/…/mysql/helper.php’; //There should be no space between the __ and the DIR, I don’t know the proper markdown here.

Looking through the include / require documentation right now, it looks like it may be better to use require than include. Include will generate a warning and keep running the application if not found where as require will error when the file is not found (rather than when the function called is not found).

Jacob

Maybe here is some useful info: http://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them/29505827#29505827

^ This means that you are not running PHP 5.5+ … Check your PHP version… it’s likely 5.4 and below.

Slim 2 will work on 5.3.3 → 5.6 … Slim 3 needs 5.5+… So you might need to downgrade if you are using php 5.3