Parse error: syntax error, unexpected '[', expecting ')' [duplicate]

走远了吗. 提交于 2019-11-26 09:54:57

问题


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

Parse error: syntax error, unexpected \'[\', expecting \')\'

the php version on my server is 5.2.17

i dnt see any problem with it, please help


回答1:


You need to be running PHP 5.4+ to use shorthand arrays




回答2:


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.

I guess, you are working with SimplXML. In this case, you should not use that line, anyway:

$media = $dc->thumbnail[0]['url'];

Note: $simpleXMLElement->childrenNodeListByName
& $simpleXMLElement['attributeValueByName']



来源:https://stackoverflow.com/questions/17411106/parse-error-syntax-error-unexpected-expecting

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