php Parse error: syntax error, unexpected '[' - php

When I run this script on my local server it works just fine. However when I run it on a hostgator server I get this error:
Parse error: syntax error, unexpected '[' in /home/user/public_html/parsing/parse.php on line 46
Line 46 is this:
$rows = [];
Any idea why this could be happening?
Thank you.
By the way I have only copied up to line 46, there are a few more lines of code than shown here.

The new array syntax [] is only available in versions 5.4 and greater.
If you are using a PHP version prior to 5.4 you have to use this syntax to create an empty array
$row = array();

Related

Weird syntax error after creating a new project in laravel 5

I created a new project: laravel new myprojectname and I am getting a blank page. First, I thought is about the permission so I gave the 777 to the storage folder, but I still had the blank page. Then I checked the logs and I saw this:
production.ERROR: Parse error: syntax error, unexpected '?', expecting
variable (T_VARIABLE) {"exception":"[object] (Symfony\\Component\\Debug
\\Exception\\FatalThrowableError(code: 0): Parse error: syntax error,
unexpected '?', expecting variable (T_VARIABLE) at /opt/lampp/htdocs
/myprojectname/vendor/symfony/routing/Route.php:53) .....
My php version is: 7.1.14 . Does anyone know why I get this ?
Thank you
The ? at line 53 is the new nullable types introduced in PHP 7.1, and you are running PHP 7.0.9, hence the reason why you're getting the error.
Laravel just upgraded to 5.6 and it requires PHP 7.13.
Also, after you upgrade your PHP, make sure you upgrade PHPUnit ~7.0, fideloper/proxy ~4.0, and Symfony ~4.0.
Follow this link here for full upgrade details.

Laravel parse error: syntax error, unexpected T_CLASS, expecting T_STRING

I developed a laravel application back in August this year, and it was working fine then. I am trying to run that application now, and it returns this error:
parse error: syntax error, unexpected T_CLASS, expecting T_STRING or
T_VARIABLE or '{' or '$' in D:\bkonme\artisan line 31
And line 31 is like this:
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
My PHP version is 5.6.14 and I am using XAMPP on windows platform. I have some idea of it happening because of some version conflict between laravel and PHP, but i don't know how to resolve that issue, any help?
Even if you have PHP/5.6.14 installed, your app is definitively not using it. You could not use class as identifier until PHP/5.5 (demo).
The feature is called Class name resolution via ::class and it's described in the Migrating from PHP 5.4.x to PHP 5.5.x chapter of the PHP manual.

Error parsing short array syntax when using json_encode()

I am sharing my work with some team. On my side, this line json_encode(['Succeeded']) works perfectly, on the team side this fails with this message
Parse error: syntax error, unexpected '[', expecting ')' in /home/app/file.php on line *
Why is this so ?
I think you might have two different versions of PHP installed.
Short array syntax was introduced in version 5.4.0. See http://php.net/manual/en/migration54.new-features.php
Therefore, the following will probably work on both:
json_encode(array('Succeeded'));
That syntax is supported only as of php 5.4.0:
http://php.net/releases/5_4_0.php

Parse error: syntax error, unexpected '[', expecting ')' [duplicate]

This question already has answers here:
PHP syntax for dereferencing function result
(22 answers)
Closed 9 years ago.
I have this linecode
$media = $dc->thumbnail->attributes()['url'];
runs fine on my local (WAMP) php 5.4.3
but when i host it on my server cpanel then it gives this error
Parse error: syntax error, unexpected '[', expecting ')'
the php version on my server is 5.2.17
i dnt see any problem with it, please help
You need to be running PHP 5.4+ to use shorthand arrays
You can't have a php 5.4.3 and a 5.2.17 with a single WAMP installation, but from your error message, i think you are using the older one.
I guess, you are working with SimplXML. In this case, you should not use that line, anyway:
$media = $dc->thumbnail[0]['url'];
Note: $simpleXMLElement->childrenNodeListByName
& $simpleXMLElement['attributeValueByName']

Activated a new WP theme, getting this error: Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}'

I am seeing this error in a file called functions.php:
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}'
I just installed a new theme in wordpress, I don't know much php.
Is this something I can fix easily?
It means the syntax of the file is invalid for the version of PHP you're running it on. It probably means your version of PHP is outdated, i.e. the theme requires PHP5 and you're running on PHP4.
That, or it's a poorly developed theme that has syntax errors.
As ** Deceze** said this issue comes when your website is running on lower version of PHP. To avoid it you can upgrade to Php5.3+ and It will start working. Also yu may get this error Error Parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING. These errors comes because the support for namespaces is not their in php versions < 5.3.

Categories