php 解析错误:语法错误,意外的 '[',期待 ')'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17411106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Parse error: syntax error, unexpected '[', expecting ')'
提问by 1Mayur
I have this linecode
我有这个行码
$media = $dc->thumbnail->attributes()['url'];
runs fine on my local (WAMP) php 5.4.3 but when i host it on my server cpanel then it gives this error
在我的本地(WAMP)php 5.4.3 上运行良好,但是当我将它托管在我的服务器 cpanel 上时,它会出现此错误
Parse error: syntax error, unexpected '[', expecting ')'
the php version on my server is 5.2.17
我服务器上的 php 版本是 5.2.17
i dnt see any problem with it, please help
我没有看到它有任何问题,请帮忙
回答by Half Crazed
You need to be running PHP 5.4+ to use shorthand arrays
您需要运行 PHP 5.4+ 才能使用速记数组
回答by pozs
You can't have a php 5.4.3 and a 5.2.17 with a single WAMP installation, but from your error message, i think you are using the older one.
您不能通过单个 WAMP 安装来安装 php 5.4.3 和 5.2.17,但是根据您的错误消息,我认为您使用的是旧版本。
I guess, you are working with SimplXML. In this case, you should not use that line, anyway:
我想,您正在使用 SimplXML。在这种情况下,无论如何您都不应该使用该行:
$media = $dc->thumbnail[0]['url'];
Note: $simpleXMLElement->childrenNodeListByName
& $simpleXMLElement['attributeValueByName']
注意:$simpleXMLElement->childrenNodeListByName
&$simpleXMLElement['attributeValueByName']