I was getting the error: "Parse error: syntax error, unexpected '['" on my website. The square brackets "[ ]" are being used for arrays. After researching the problem I realized that my developer environment was using PHP 5.6 and PHP 5.4 and above all the use of the following syntax: "$myArray = [ ];" However, PHP 5.3 does not allow this type of syntax. So, yesterday I had godaddy change my account from a classic hosting to a web hosting. Once that was all moved over, I was able to go into my account and switch the PHP version from 5.3 to 5.6, BUT, I am still unable to use the square bracket syntax. I've chatted with tech support and they say that 5.6 is installed correctly and everything is working on their end. So, what am I missing? I read a note somewhere about possibly needing to change the php.ini file to be php56.ini but I don't know where that file is. Any help would be much appreciated!
Solved! Go to Solution.
I know I may be stating the blindingly obvious here, but usually this error points to no closing bracket to match, or one too many, or just simply something else was expected, like a '(' instead.
Welcome to 'php hunt-the-thimble'....... it's what developers get paid for. It's very frustrating but you will have to go over your code with a fine tooth comb. Because even were we able to see your code, it may take us a long while to see the mistakes you have made in the syntax. The php website is best for lessons.
One clue though, the error line number....... the error is usually on the line above this...
Thank you for the reply @Anonymous . So, unfortunately there is nothing wrong with the syntax. It's a problem with the PHP version and I'm trying to figure out how (or if) I'm able to get PHP configured correctly on GoDaddy.
Let me give you a bigger picture of what I'm battling against. On my developer machine I have PHP 5.6.25 installed. I can run the following code with no problems:
$subjects = [ // this is the "line 4 that the error complains about"
['id' => '1', 'position' => '1', 'visible' => '1', 'menu_name' => 'About Globe Bank'],
['id' => '2', 'position' => '2', 'visible' => '1', 'menu_name' => 'Consumer'],
['id' => '3', 'position' => '3', 'visible' => '1', 'menu_name' => 'Small Business'],
['id' => '4', 'position' => '4', 'visible' => '1', 'menu_name' => 'Commercial'],
However, when I push this file to my GoDaddy account, I get the syntax error. When I first got the error and started doing my homework and research, I discovered that this syntax is not legal with PHP 5.3. So, I checked my GoDaddy account and sure enough, it was running PHP 5.3. So, I asked GoDaddy to move me from the "classic" hosting to the "web" hosting so that I could upgrade to PHP 5.6.
Well, on my account it shows that I have PHP 5.6 installed. However, I am still unable to run this code AND when I run the code <?php phpinfo(); ?> it actually says that I am running PHP version 5.2.17
So, my ultimate question is: How do I get my GoDaddy server to actually switch over and use the installed PHP 5.6 instead of the old PHP 5.2.17 that it currently seems to really be attached to?
ahhh, a different problem here. One where I usually would go round and hammer on Godaddy's front door....... "You sold me 'X' but I have 'Y'.
I hope you have a VPS or your own private server for the next bit....... otherwise you may have a long call with support.
Issue finally got bumped up to tier2 support. Turns out that either something was being cached after having been ported over from "classic" hosting to "web" hosting or there was some config file (which I couldn't see) that was forcing the server to use the old PHP 5.3 version instead of allowing it to use the new PHP 5.6 version. So, they sandboxed everything and created a new WebRoot, which then fixed the problem.
I see this sometimes, if there's an addhandler line in a .htaccess file, 2gh / 4gh hosting will use that setting over whatever you've set in your control panel.
Parse error: syntax error, unexpected '[' in /home/content/53/2521453/html/wp-content/plugins/sydney-toolbox/sydney-toolbox.php on line 100