Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.