0

I'm getting the following error message in log:

2014/08/05 00:13:18 [error] 816#0: *23 FastCGI sent in stderr: "PHP message: PHP Parse
error: syntax error, unexpected '[' in /var/www/example.php on line 32" while reading
response header from upstream, client: 1.1.1.1, server: example.com, request: "GET
/example.php HTTP/1.1",upstream: "fastcgi://unix:/dev/shm/php-fpm-www.sock:", host:
"example.com"

The example.php line 32 is:

return $fb->api('/me/scores/','GET')['data'][0]['score'];

I've restarted php5-fpm (I'm using PHP 5.3), nginx and the Ubuntu server itself with no luck. Any idea what is going on? Thanks!

1 Answer 1

0

I think that the problem is that you can't use function array deferencing, that is the square brackets after a function call. From PHP 5.4 you can. See also this question PHP Array Syntax Parse Error Left Square Bracket "["

So try to assign the result of the function call to a variable, and the use it. Like this:

$response = $fb->api('/me/scores/','GET');
return $response['data'][0]['score'];
Sign up to request clarification or add additional context in comments.

3 Comments

thought that might be the case, how could I do it in PHP 5.3 for that line?
Ah! Perfect and makes complete sense :) Thank you! Can accept the answer in 6 minutes, thanks again Claudio.
I have added a sample code of a simple workaround. It should work, try it and let me know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.