【问题标题】:PHP FastCGI Parse errorPHP FastCGI 解析错误
【发布时间】:2014-09-27 13:31:40
【问题描述】:

我在日志中收到以下错误消息:

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"

example.php 第 32 行是:

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

我重新启动了 php5-fpm(我使用的是 PHP 5.3)、nginx 和 Ubuntu 服务器本身,但没有成功。知道发生了什么吗?谢谢!

【问题讨论】:

    标签: php nginx fastcgi


    【解决方案1】:

    我认为问题在于你不能使用函数数组deferencing,即函数调用后的方括号。从 PHP 5.4 你可以。另请参阅此问题PHP Array Syntax Parse Error Left Square Bracket "["

    所以尝试将函数调用的结果分配给一个变量,并使用它。像这样:

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

    【讨论】:

    • 认为可能是这种情况,我怎么能在 PHP 5.3 中为该行做到这一点?
    • 啊!完美且完全有意义:) 谢谢!可以在 6 分钟内接受答案,再次感谢 Claudio。
    • 我添加了一个简单解决方法的示例代码。它应该可以工作,试试看,然后告诉我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-17
    • 2015-11-05
    • 1970-01-01
    相关资源
    最近更新 更多