【问题标题】:What? Parse error: syntax error, unexpected T_STRING in /file/path什么?解析错误:语法错误,/file/path 中出现意外的 T_STRING
【发布时间】:2013-12-27 11:04:28
【问题描述】:

我收到以下行的此错误:

\Codebird\Codebird::setConsumerKey( $auth_args['consumer_key'], $auth_args['consumer_secret'] );

这是我刚刚安装在服务器上的 wordpress 模板。它适用于我的 WAMP 家庭服务器,但不适用于非自托管服务器。不确定是否是不同的 PHP 版本有问题。

这里是第 9 行:

class Jed_Widget_Latest_Tweets extends WP_Widget {
function __construct() {
    parent::__construct(false, $name = 'Jednotka Twitter Widget', array( 'description' => 'Twitter profile widget for your site.' ) );
}

function retrieve_tweets( $widget_id, $instance, $auth_args ) {

    if ( !empty($auth_args['consumer_key']) && !empty($auth_args['consumer_secret']) ) {
        \Codebird\Codebird::setConsumerKey( $auth_args['consumer_key'], $auth_args['consumer_secret'] );
        $cb = \Codebird\Codebird::getInstance();
        $cb->setToken( $auth_args['access_token'], $auth_args['access_secret'] );
        $timeline = $cb->statuses_userTimeline( 'screen_name=' . $instance['screen_name']. '&count=' . $instance['num_tweets'] . '&exclude_replies=true' );
        return $timeline;
    }
    else {
        return 'Authentication to twitter server failed. Please make sure that your "consumer key" and "consumer secret" are not empty';
    }

}

function save_tweets( $widget_id, $instance, $auth_args ) {
    $timeline = $this->retrieve_tweets( $widget_id, $instance, $auth_args );
    $tweets = array( 'tweets' => $timeline, 'update_time' => time() + ( 60 * 5 ) );
    update_option( 'my_tweets_' . $widget_id, $tweets );
    return $tweets;
}

function get_tweets( $widget_id, $instance, $auth_args ) {
    $tweets = get_option( 'my_tweets_' . $widget_id );
    if( empty( $tweets ) OR time() > $tweets['update_time'] ) {
        $tweets = $this->save_tweets( $widget_id, $instance, $auth_args );
    }
    return $tweets;
}

【问题讨论】:

  • 我很确定你的问题是 PHP 版本。另一台服务器上的 PHP 版本可能不支持命名空间,所以它不知道如何处理反斜杠。

标签: php wordpress twitter syntax-error


【解决方案1】:

确保您使用的是 PHP 5.3 或更高版本,并且声明了命名空间,否则解释器会认为 \Codebird\Codebird 是一组随机字符

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-24
    • 1970-01-01
    • 1970-01-01
    • 2013-05-13
    • 2014-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多