eldan88 Posted August 4, 2013 Share Posted August 4, 2013 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 More sharing options...
KevinM1 Posted August 4, 2013 Share Posted August 4, 2013 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. Link to comment https://forums.phpfreaks.com/topic/280808-need-help-adding-args-for-an-instance/#findComment-1443387 Share on other sites More sharing options...
eldan88 Posted August 4, 2013 Author Share Posted August 4, 2013 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?" Link to comment https://forums.phpfreaks.com/topic/280808-need-help-adding-args-for-an-instance/#findComment-1443388 Share on other sites More sharing options...
AbraCadaver Posted August 5, 2013 Share Posted August 5, 2013 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); } Link to comment https://forums.phpfreaks.com/topic/280808-need-help-adding-args-for-an-instance/#findComment-1443589 Share on other sites More sharing options...
eldan88 Posted August 9, 2013 Author Share Posted August 9, 2013 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? Link to comment https://forums.phpfreaks.com/topic/280808-need-help-adding-args-for-an-instance/#findComment-1444088 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.