Twilio api解析错误:意外T_CONST,期待T_OLD_FUNCTION或T_FUNCTION或T_VAR或'}'

时间:2013-10-22 15:12:06

标签: php const user-agent twilio

我有PHP 5.4.21

我正在使用可在浏览器中正常工作的Twilio API,但在命令行模式下,我收到以下错误:

<b>Parse error</b>:  syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in <b>sms/Services/Twilio.php</b> on line <b>36</b>

指定文件的第36行是以下类的一部分,请参阅我在说明第36行的注释。

我根据一些初始反馈请求添加了所有代码行,这些代码行在36行之前和紧接在第36行之后,以显示这些行。

<?php
function Services_Twilio_autoload($className) {
    if (substr($className, 0, 15) != 'Services_Twilio') {
        return false;
    }
    $file = str_replace('_', '/', $className);
    $file = str_replace('Services/', '', $file);
    return include dirname(__FILE__) . "/$file.php";
}

spl_autoload_register('Services_Twilio_autoload');

/**
 * Create a client to talk to the Twilio API.
 *
 *
 * :param string               $sid:      Your Account SID
 * :param string               $token:    Your Auth token from
 *      twilio.com/user/account
 * :param string               $version:  API version to use
 * :param $_http:    A HTTP client for making requests.
 * :type $_http: :php:class:`Services_Twilio_Http`
 * :param int                  $retryAttempts:
 *      Number of times to retry failed requests. Currently only idempotent
 *      requests (GET's and DELETE's) are retried .
 */

class Services_Twilio extends Services_Twilio_Resource
{
    /* this is Line 36... */
    const USER_AGENT = 'twilio-php/3.12.0';

    protected $http;
    protected $retryAttempts;
    protected $last_response;
    protected $version;
    protected $versions = array('2008-08-01', '2010-04-01');

    public function __construct(
        $sid,
        $token,
        $version = null,
        Services_Twilio_TinyHttp $_http = null,
        $retryAttempts = 1
    ) {
              $_http = new Services_Twilio_TinyHttp(
                  "https://api.twilio.com",
                  array("curlopts" => array(
                      CURLOPT_USERAGENT => self::USER_AGENT,
                      CURLOPT_HTTPHEADER => array('Accept-Charset: utf-8'),
                      CURLOPT_CAINFO => dirname(__FILE__) . '/cacert.pem',
                  ))
              );
    }
}
?>

1 个答案:

答案 0 :(得分:1)

从我原来的评论:

据我所知,最可能的解释是您的命令行正在为您的Web服务器运行不同版本的PHP。尝试在命令行运行php -v以确认它正在运行您期望的版本。

OP的回复

  

@Spudley,谢谢你的反馈。看起来你是唯一一个真正阅读我的帖子而不做假设的人。正如你所说,我运行“php -v”,这就是我得到的,所以很明显我运行的是早期版本的PHP:PHP 4.4.9(cgi-fcgi)(内置:2013年7月22日09:48:43 )版权所有(c)1997-2008 PHP Group Zend Engine v1.3.0,版权所有(c)1998-2004 Zend Technologies

所以,我们走了,这显然是问题所在。你那里有PHP 4.4。这需要去。

解决方案摆脱旧的破坏版本的PHP,并确保您的命令行php运行与您的Web服务器相同的版本。

您尚未指定正在运行的操作系统,这显然会对如何进行卸载产生重大影响。

如果你可以在你的卸载工具中找到旧的PHP版本,那就去做吧,希望你能开始通过魔术来获取更新的PHP版本。如果没有,那么根据事情的配置方式,您可能会发现实现此目的的最简单方法是卸载两个 PHP版本,然后重新安装5.4版本。