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

爷,独闯天下 提交于 2019-11-27 05:51:23

问题


This question already has an answer here:

  • PHP syntax for dereferencing function result 22 answers

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


回答1:


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



来源:https://stackoverflow.com/questions/16358973/parse-error-syntax-error-unexpected-with-php-5-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!