jd2007 Posted August 16, 2007 Share Posted August 16, 2007 In a child class's __construct, how to access parent class's __construct ? Quote Link to comment https://forums.phpfreaks.com/topic/65238-in-a-child-classs-__construct-how-to-access-parent-classs-__construct/ Share on other sites More sharing options...
trq Posted August 16, 2007 Share Posted August 16, 2007 parent::__construct(); Quote Link to comment https://forums.phpfreaks.com/topic/65238-in-a-child-classs-__construct-how-to-access-parent-classs-__construct/#findComment-325766 Share on other sites More sharing options...
jd2007 Posted August 17, 2007 Author Share Posted August 17, 2007 in the child class's __construct , the code is: function __construct($b, $c) { parent::_construct(); $this->y=$b; $this->z=$c } in the parent class's __construct , the code is: function __construct($a) { $this->x=$a; } if i create an object of the child class, if i want to use properties in both parentand child class __construct what to do ? Quote Link to comment https://forums.phpfreaks.com/topic/65238-in-a-child-classs-__construct-how-to-access-parent-classs-__construct/#findComment-326379 Share on other sites More sharing options...
trq Posted August 17, 2007 Share Posted August 17, 2007 Im not 100% I understand your question. Does this explain any? <?php class p { // parent class. function __construct($a) { echo "this is $a within parent"; } } class c extends p { // child class function __construct($a,$b,$c) { parent::__construct($a); echo "this is $b within child"; echo "this is $c within child"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/65238-in-a-child-classs-__construct-how-to-access-parent-classs-__construct/#findComment-326387 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.