简体   繁体   中英

PHP FastCGI Parse error

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM