Parse error: syntax error, unexpected T_VARIABLE in Xro_config.php on line 21
-
14-12-2019 - |
Question
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'
);
}
}
OTHER TIPS
You cannot use $this
when declaring variables. $this
only exists in member functions of the class. You will have to initiate the variable in the constructor of the class.
Edit
It looks like you are using static methods/variables for everything else. I assume you want this to be static too. But since you can't initialize a varible with a function, and you aren't going to be calling a constructor you should probably turn the $signatures
variable into a method:
<?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'
);
}
}