Jump to content

Need help adding args for an instance


eldan88

Recommended Posts

Hey,

 

 

I am trying to add static arguments in a new instance, but for some reason dreamweaver is showing it as invalid. Any suggestions on what I am doing incorrectly?

class OrderConfirmation {

static public $apiversion = "2010-04-01";
static public $sid = "123";

public $confirmation_number = 1;
public $to_number = 3478870121;

public $client = new Services_Twilio(self::$sid); // This line is giving me an error?
Link to comment
https://forums.phpfreaks.com/topic/280808-need-help-adding-args-for-an-instance/
Share on other sites

Property initialization is a bit tricky. You can only initialize a property directly if its value can be determined at compile time. Try initializing it in a constructor instead.

Hey Kevin,

 

 I'm sorry, I don't understand what you mean by this. What do you mean by property initialization? And what do you mean by "You can only initialize a property directly if its value can be determined at compile time?"

Hey Kevin,

 

 I'm sorry, I don't understand what you mean by this. What do you mean by property initialization? And what do you mean by "You can only initialize a property directly if its value can be determined at compile time?"

 

This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.

 

Initialization is what you are doing there in your class.  You are initializing the vars and they must be set to a constant value and something that can be evaluated at compile time, which an object instantiation cannot.

 

Try what Kevin suggested:

class OrderConfirmation {

static public $apiversion = "2010-04-01";
static public $sid = "123";

public $confirmation_number = 1;
public $to_number = 3478870121;

public function __construct() {
    $this->client = new Services_Twilio(self::$sid);
}

 

This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.

 

Initialization is what you are doing there in your class.  You are initializing the vars and they must be set to a constant value and something that can be evaluated at compile time, which an object instantiation cannot.

 

Try what Kevin suggested:

class OrderConfirmation {

static public $apiversion = "2010-04-01";
static public $sid = "123";

public $confirmation_number = 1;
public $to_number = 3478870121;

public function __construct() {
    $this->client = new Services_Twilio(self::$sid);
}

Thank you for your response. I understood everything you said, but I don't get what you mean by "You are initializing the vars and they must be set to a constant value"

 

How do I set them to a constant value?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.