PHP error unexpected '[' with php 5.3 [duplicate] - php

This question already has an answer here:
PHP unexpected '['
(1 answer)
Closed 8 years ago.
I can not use a newer PHP version then 5.3 and i get this error message:
**Parse error: syntax error, unexpected '[' in PATH/product.php on line 17**
I founded on this page that is php version problem, how can i solve this in php 5.3?
The code on this line is exactly:
$_productids = [];

Old version doesn't support this syntax. Update this to:
$_productids = array();

Use old array syntax:
$_productids = array();

Related

PHP Parse error: syntax error, unexpected '[' [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 got few lines producing error 500. The error log says:
PHP Parse error: syntax error, unexpected '[' in...
and the lines are:
$catids[] = $params->get('catid');
and after commenting it out, this one comes up:
$return_category[] = self::_getCategoryInfor($tg, $params)[0];
How can i modify them in order to match with new PHP versions and solve the error 500?
From your code, I do not see code that may triggered this parse error. Try change your code so it becomes:
$categories = self::_getCategoryInfor($tg, $params);
$return_category[] = $categories[0];
This is the expression causing the error:
self::_getCategoryInfor($tg, $params)[0];
Function array dereferencing was added in PHP 5.4. Your code will generate a parse error on 5.3 or lower:
https://secure.php.net/manual/en/migration54.new-features.php

Parse error: syntax error, unexpected '[' in C:\xampp\htdocs\twitter\application\controllers\twitteroauth.php on line 117 [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I am using twitterauth.php for getting twitter data in codeigniter php.
It gives me error
Parse error: syntax error, unexpected '[' in C:\xampp\htdocs\twitter\application\controllers\twitteroauth.php on line 117
Line 117 is
public function oauth($path, array $parameters = [])
You need PHP 5.4 or over to use square brackets as array. Upgrade PHP or use array().

Elgg Installation Synatx Error (Unexpected '[') [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 8 years ago.
I am having trouble with my elgg installation for my website. Every time I load the "install.php" in the root directory, I keep getting this error:
Parse error: syntax error, unexpected '[' in (Root)/engine/classes/Elgg/Di/ServiceProvider.php on line 194
Here is line 194 in that file:
$params = $c->config->get('cookies')['session'];
I have PHP version 5.3.13. Can anyone help?
Arrays can't be referenced directly from a return object in PHP below 5.4.
[Documentation]
You can't do this:
$params = $c->config->get('cookies')['session'];
But you CAN do this:
$cookies = $c->config->get('cookies');
$params = $cookies['session'];
Or you can just upgrade your PHP installation.
You can't do this because you don't have PHP version 5.4 or higher!
So change this:
$params = $c->config->get('cookies')['session'];
to this:
$params = $c->config->get('cookies');
$params = $params['session'];
For more information about array dereferencing see the manual: http://php.net/manual/en/language.types.array.php
And a quote from there:
As of PHP 5.4 it is possible to array dereference the result of a function or method call directly. Before it was only possible using a temporary variable.

SVN Commit failed with syntax error, unexpected '[' [duplicate]

This question already has answers here:
Unexpected bracket '[' - PHP [duplicate]
(3 answers)
Closed 9 years ago.
I 'm try to commit this code to my server from my Ubuntu server
$me = $this->fetchAll(array('id'=>$Id,'ce'=>$e), array('cr'=>array('$slice' =>[$offset, $limit])));
but it return
PHP Parse error: syntax error, unexpected '[' in - on line 114
MSG: Failed to checkin branches/myFile.php, PHP said
what is the wrong with '$slice' =>[$offset, $limit] in order to commit it to my server
The []-short-array notation was introduced with PHP 5.4. Some *ix distros have still not introduced this new version to their default repos. Make sure your server uses php5.4 to parse that specific file. For the time beeing I'd recommed to use the 'old' array notation.
http://www.php.net/manual/en/migration54.new-features.php
You can't do it like that. Try this:
'$slice' => $offset . ', ' . $limit
I think that's what you're looking for.

Parse error: syntax error, unexpected '[' with php 5.3 [duplicate]

This question already has answers here:
PHP syntax for dereferencing function result
(22 answers)
Closed 9 years ago.
My script is working really fine on my xampp. Now I tried to upload it on the server, but it spat directly a
Parse error: syntax error, unexpected '['
in my face. :(
The line which its mocking about is this one:
$item = $xml->xpath($path)[0];
And I have no idea what is wrong. I tried to look on the php 5.3 changelog but did not found anything about it. (Because I have 5.3 on the server, and on xampp its an olderversion)
The whole code block looks like this:
$path = '//item[#id="'.$id.'"]';
if ($xml->xpath($path)) {
$item = $xml->xpath($path)[0];
} else {
die('<p class="error">Script Error: Code 101 - Please contact administrator</p>');
}
I am thankful for any help, I cannot seach [ with google and have no idea where it could come from, since on xampp its working fine
Try this
$item = $xml->xpath($path);
$item = $item[0];

Categories