0

I'm using Slim Framework, and have set-up a very simple API to retrieve data from a database. This works flawlessly on my local machine, OS X El Capitan.

But - when moving the files to a shared hosting environment, all the routes throw 500 errors, with this error specifically:

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

Line 12 is:

function simpleDispatcher(callable $routeDefinitionCallback, array $options = []) {

I can't work out why it is throwing a parse error on this line, and why it works on my local but not on shared, both running a version of PHP 5.5. Does anybody have any ideas on why this could be?

alexw
  • 8,468
  • 6
  • 54
  • 86
JWDev
  • 856
  • 1
  • 10
  • 22

2 Answers2

3

You are using an old PHP version in your server which doesn't properly support Slim router. You should upgrade to PHP 5.5 according to the minimum requirements of slim framework. [] style arrays do not work in older versions of PHP, hence the error message.

Gogol
  • 3,033
  • 4
  • 28
  • 57
  • 1
    either that or revise the code accordingly – andrew Jun 16 '16 at 10:19
  • 1
    Upgrading is definitely the way to go. PHP 5.3 reached its end of life [almost two years ago](http://php.net/eol.php). Even PHP 5.5 will reach its end of life on [10 July 2016](http://php.net/supported-versions.php). – alexw Jun 16 '16 at 22:03
1

You need to replace the array declaration with the older style like this:

function simpleDispatcher(callable $routeDefinitionCallback, array $options = array()) {

And on all other occurrences in your code. Or if possible, just upgrade the PHP version that'll eventually support square brackets as array declaration syntax.

Rahul M
  • 1,498
  • 12
  • 19