解析错误:语法错误,PHP 5.3出现意外"["

问题描述:

我的脚本在xampp上运行正常.现在,我尝试将其上传到服务器上,但是直接吐出了一个

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

在我的脸上. :(

它嘲笑的那一行是这样的:

The line which its mocking about is this one:

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

我不知道出什么问题了.我试图查看php 5.3 changelog,但未找到任何有关它的信息. (因为我在服务器上安装了5.3,而在xampp上安装了旧版本)

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)

整个代码块如下所示:

$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>');
}

我非常感谢您的帮助,我无法与[google联系,也不知道它可能来自哪里,因为在xampp上可以正常工作

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

尝试一下 $item = $xml->xpath($path);
$item = $item[0];

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