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? Link to comment https://forums.phpfreaks.com/topic/170792-solved-class-arguments/ 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(); Link to comment https://forums.phpfreaks.com/topic/170792-solved-class-arguments/#findComment-900734 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.