phparrayssyntaxsyntax-errorsquare-bracket

Parse error: syntax error, unexpected '[' while declaring an array with square braces on a version below PHP5.4


I have:

Recently, I have reinstalled the whole VPS. My problem is with a statement like this:

function foo($arr) {
    return $arr;
}
foo(['foo1','foo2','foo3'])

It works on my pc, and used to work on the server (same installation) but now it gives an error such as:

Parse error: syntax error, unexpected '[' in /home/Websites/Domains/squazza/php/db.php on line 261

Replacing the [ ] with Array( ) does fix the problem.

Now I assume that this problem is related to php.ini, so I am asking what setting could possibly be affecting this kind of behavior and why?


Solution

  • If you look at the documentation that short syntax is only avaible in php 5.4+ I suspect your php versions are different.

    This list of new features in PHP5.4 maybe of some use to you.