Search code examples
phparraysvariablessyntax-errorparse-error

Parse error: syntax error, unexpected T_VARIABLE in Xro_config.php on line 21


I have been puzzled by this weird problem and it got me stuck. Please take a look. May be a differnt eye wil catch the error. I have pasted the code below so you may see where the error occurs at line 21 ( 'consumer_key' => $this->get_consumer_key(),).

Thanks for your help in advance. Cheers :)

<?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;
        }
              }
?>

Solution

  • You should initialize variables on the class constructor.

    For example:

    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'
           );
    
      }
    }