Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 258
Owl Avatar asked May 03 '13 12:05

Owl


1 Answers

Try this $item = $xml->xpath($path);
$item = $item[0];

like image 178
Willy Pt Avatar answered Oct 29 '22 00:10

Willy Pt