corillo181 Posted September 4, 2007 Share Posted September 4, 2007 so i got a class with some methods and stuff.. <?php class test1{ protected $id; protected $name; public function __construct($id,$name){ $this->id = $id; $this->name = $name; } } ?> i have done it before but i forgot how do i call it on a child class. <?php class test2 extends test1{ public __construct($id,$name,$lastname){ parent::__construct($id,$name); $this->lastname = $lastname; } public function getfullname(){ print "you are {$this->name},{$this->lastname}"; } } ?> can any one please tell me how to do it? Quote Link to comment https://forums.phpfreaks.com/topic/67858-extending-php-classes/ Share on other sites More sharing options...
teng84 Posted September 4, 2007 Share Posted September 4, 2007 is there an error or declare your variables as public on that class you extend Quote Link to comment https://forums.phpfreaks.com/topic/67858-extending-php-classes/#findComment-341100 Share on other sites More sharing options...
corillo181 Posted September 4, 2007 Author Share Posted September 4, 2007 i'm just try find out how would i call properties in the parent to the child. if i have a statment like test1= new test1('1','Jay'); test2 = new test2('lastname'); test2->getfullname(); assuming the child class contrus tlooks like this __construct(lastname){ parent::__construct($id,$name); $this->lastname; } Quote Link to comment https://forums.phpfreaks.com/topic/67858-extending-php-classes/#findComment-341114 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.