Garethp Posted August 18, 2009 Share Posted August 18, 2009 Ok, so I want to make a class where I have global variables that I can set as I call the class. Like this class Something($Text) { function T() { echo $this->Text; } } $v = new Something('Hello World'); $v->T(); I know I could set it with a function, but I'd rather do it with the example above. Can it be done? Quote Link to comment Share on other sites More sharing options...
trq Posted August 18, 2009 Share Posted August 18, 2009 Its called a __construct. Its all covered in the man. class Something { private $Text; public function __construct($s) { $this->Text = $s; } function T() { echo $this->Text; } } $v = new Something('Hello World'); $v->T(); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.