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

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.

Related

PHP: xpath not working on php5.3 because of unexpected "[" [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I was running the following line on PHP5.4 without any problem:
$lstContent = $data->xpath("/response/lst[#name='highlighting']")[0]->lst[$i]->arr->str;
But now on PHP5.3 (production system) I get the following error:
Parse error: syntax error, unexpected '[' in /var/www/html/upload/inc_suche_code.php on line 153
Any ideas for a quick fix?
Updating PHP won't work for me.
In older versions of PHP you can not access array values directly on variables that are the result of a function. You have to split up the expression using a temporary variable.
$result = $data->xpath("/response/lst[#name='highlighting']");
$lstContent = $result[0]->lst[$i]->arr->str;
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.
Source: http://php.net/manual/en/language.types.array.php
Edit: Obligatory "you should also consider upgrading your PHP version". This annoying limitation was fixed ages ago, not to mention that the 5.3 had its end of life in 2014, meaning it has not received security upgrades since.

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

Unexpected '[' error [duplicate]

This question already has answers here:
PHP Difference between array() and []
(5 answers)
Closed 8 years ago.
I have an Index php page that contains a code that prints the values of an array $a=['f','a','b'];.
The code works fine on WAMP server on my computer however when I upload the page online on a server like 000webhost an error comes up that says there is unexpected '[' on line of the array. Does anyone know why this happens?
Your PHP version doesn't support the [] notation, this kind of notation is available from PHP 5.4, use $a = array('f','a','b'); instead.

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

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();

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