Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected bracket '[' - PHP [duplicate]

I'm writing a small repository for my little app team's Java code, and I have this error all over my code.

$base = explode(".", $class)[0];

The problem occurs only with this one line of code, every time. As far as I know, the above is correct PHP syntax, so what's going on?

Parse error: syntax error, unexpected '[' in .../mitc/code/index.php on line 27

If you'd like to see the error, it's at http://chancehenrik.x10.mx/mitc/code/ and elsewhere on my site.

like image 664
Sammi De Guzman Avatar asked Dec 11 '22 18:12

Sammi De Guzman


1 Answers

That's called array dereferencing and only works in PHP 5.4+. You're probably running PHP 5.3.x wherever you are getting that error.

See results based on different PHP versions

like image 139
John Conde Avatar answered Dec 14 '22 08:12

John Conde