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

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']

Related

Google analytics api showing Parse error: syntax error, unexpected '=' in /home2/.../.../vendor/laravel/framework/src/Illuminate/Support/Arr.php [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 4 years ago.
I am working on a google analytics dashboard which will display marketing campaign results for the customers. I am using google analytics api but I keep getting this error ( Parse error: syntax error, unexpected '=' in /home2/.../.../vendor/laravel/framework/src/Illuminate/Support/Arr.php on line 388). I searched about the error and found that it is because of a mismatch of the php version between apache server and CLI.my CLI php version used to be 7.1.12 and my apache version was 7.1.14. I upgraded it to 7.1.14 but I am still facing the same error.
This is the offending line from Arr.php:
[$value, $key] = static::explodePluckParameters($value, $key);
It seems your PHP server is still running version < 7.1.0 and it doesnt support this array notation
To test it, you can use following code (php 5.x and php < 7.1.0 throws parse error):
[$value, $key] = explode("|",'some|thing');
var_dump($value,$key);

PHP Parse error: syntax error, unexpected '?' [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I have read a lot syntax error but seldom on the error of '?'
I also saw a few post that stated this might be due to old PHP version.
So my question is does PHP5.6 isn't enough? I am using Godaddy as my host and PHP5.6 is the highest they provide.
The full error description is:
PHP Parse error: syntax error, unexpected '?' in G:\PleskVhosts\tohokiwatch.com\httpdocs\cart\vendor\illuminate\database\Eloquent\Model.php on line 579
MyPHP page stated version 5.5.30:
But my GoDaddy page stated version 5.6.30
The null coalesce operator, ?? does not exist in php 5.5 or 5.6, it was added in php 7.0

Ajax, unexpected symbol? [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']

Unexpected '[' - no error on localhost but there is one on server [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
$query_var[] = '`'.array_keys($activeFilters)[$i].'` LIKE concat(\'%\',:'.array_keys($activeFilters)[$i].',\'%\')';
Parse error: syntax error, unexpected '['
So the following line generates an error in my Xampp apache server on localhost the error isn't occurring. Also on my server there was an error also with
$query_var = [];
but I changed it to $query_var = array(); and the error wanst appearing it was also a unexpected [
I am nearly sure it has something to do with the PHP version or something like that
correct, its a php version issue as of php 5.4 you can use
$query_var = [];
http://php.net/manual/en/migration54.new-features.php
so your host is running an older php version.

i have error in laravel on function /vendor/guzzlehttp/psr7/src/functions.php on line 77 [duplicate]

This question already has an answer here:
Difference in accessing arrays in PHP 5.3 and 5.4 or some configuration mismatch?
(1 answer)
Closed 7 years ago.
I upload laravel 4 files on shared server
and then i see this error.
Parse error: syntax error, unexpected '[' in . /vendor/guzzlehttp/psr7/src/functions.php on line 77
in line 77:
function stream_for($resource = '', array $options = [])
Short array syntax [] was added in PHP 5.4, so I guess you're running some older version of PHP on the shared server. Normally replacing [] with array() would help, but here it is an external vendor package so it's not advised to modify the code as changes would be overwritten when vendor package is updated. Other than that the only way to fix that issue is to use newer version of PHP.

Categories