10

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

3
  • Because of the php version. Commented Jul 1, 2013 at 18:24
  • 3
    5.2 and 5.4 are worlds apart my friend. Commented Jul 1, 2013 at 18:25
  • stackoverflow.com/questions/742764/… Commented Jul 1, 2013 at 18:25

2 Answers 2

20

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

Sign up to request clarification or add additional context in comments.

2 Comments

$mediaArr = $dc->thumbnail->attributes(); $media = $mediaArr->url[0]; this did it
You can call properties on a chained method in your version if you want to shorten it up: $mediaArr = $dc->thumbnail->attributes()->url[0]
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.