【问题标题】:Parse error: syntax error, unexpected T_VARIABLE in Xro_config.php on line 21解析错误:语法错误,第 21 行 Xro_config.php 中的意外 T_VARIABLE
【发布时间】:2012-03-14 18:07:34
【问题描述】:

我一直对这个奇怪的问题感到困惑,它让我陷入了困境。请看一下。可能是另一只眼睛会发现错误。我已经粘贴了下面的代码,因此您可能会在第 21 行看到错误发生的位置('consumer_key' => $this->get_consumer_key(),)。

提前感谢您的帮助。干杯:)

<?php
    class Xro_config {

        //Set to true to enable Oauth debugging
        protected $debug = true;
        // public, partner, or private
        protected $xro_app_type = "Public"; 

        /* 
        * Xero Calback URL
        */
        protected static $_oauth_callback = '';

        /*
        * Xero Signature keys
        */
        protected $signatures = array(
            // local
            'consumer_key' => $this->get_consumer_key(),
            'shared_secret' => $this->get_shared_secret(),
            // 'rsa_private_key' => '/[path]/[privatekey].pem',
            // 'rsa_public_key' => '/[path]/[publickey].cer'
         );

        protected static $_consumer_key;
        protected static $_shared_secret;

        /**
         * Sets the Oauth Callback URL. The Default is in an emptystring
         * @param string $URL
         */
        public static function set_oauth_callback($URL) {
            self::$_oauth_callback = $URL;
        }

        /**
        * Gets the oauth_callback
        */
        function get_oauth_callback(){
            return self::$_oauth_callback;
        }

        /**
         * Sets the Cusumer API KEys
         * @param string $consumerkey
         */
        public static function set_consumer_key($consumerkey) {
            self::$_consumer_key = $consumerkey;
        }

        /**
         * Sets the Cusumer API KEys
         * @param string $sharedSecret
         */
        public static function set_shared_secret($sharedSecret) {
            self::$_shared_secret = $sharedSecret;
        }

        /* 
        * Get Signature Keys 
        */
        function get_consumer_key(){
            return self::$_consumer_key;
        }

        function get_shared_secret(){
            return self::$_shared_secret;
        }
              }
?>

【问题讨论】:

    标签: php arrays variables syntax-error parse-error


    【解决方案1】:

    声明变量时不能使用$this$this 只存在于类的成员函数中。您必须在类的构造函数中初始化变量。

    编辑

    看起来您正在对其他所有内容使用静态方法/变量。我假设您也希望它是静态的。但是由于您不能使用函数初始化变量,并且您不会调用构造函数,您可能应该将 $signatures 变量转换为方法:

    <?php
    
     class Xro_config {
     ...
      protected static function signatures() {
         return rray(
           // local
           'consumer_key' => self::get_consumer_key(),
           'shared_secret' => self::get_shared_secret(),
           // 'rsa_private_key' => '/[path]/[privatekey].pem',
           // 'rsa_public_key' => '/[path]/[publickey].cer'
        );
      }
     }
    

    【讨论】:

    • 我最终选择了您建议的 __construct 初始化方法。谢谢杰森。
    【解决方案2】:

    你应该在类构造函数上初始化变量。

    例如:

    class Xro_config {
    
      protected $signatures; 
    
      public function __construct()
      {
       $this->signatures = array(
              // local
              'consumer_key' => $this->get_consumer_key(),
              'shared_secret' => $this->get_shared_secret(),
              // 'rsa_private_key' => '/[path]/[privatekey].pem',
              // 'rsa_public_key' => '/[path]/[publickey].cer'
           );
    
      }
    }
    

    【讨论】:

    • 我最终得到了完全一样的东西。谢谢:)
    猜你喜欢
    • 2015-05-11
    • 2013-03-10
    • 2017-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多