Parse error: syntax error, unexpected '[',

2019-01-06 20:56发布

This question already has an answer here:

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

2条回答
爷、活的狠高调
2楼-- · 2019-01-06 21:53

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

查看更多
Fickle 薄情
3楼-- · 2019-01-06 21:57

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

查看更多
登录 后发表回答