hkothari Posted November 1, 2009 Share Posted November 1, 2009 I have a base class: class Base { function __construct($param1, $param2, $param3) { //does some stuff } } and a child class class Child extends Base { function __construct($param1, $param2) { //what I want to do here is call the parent constructor with the two given parameters and supply the third one. } } Is it possible to call the parent constructor when overloading it in the child class? Would calling: parent::__construct($param1, $param2, "third param"); work? Quote Link to comment https://forums.phpfreaks.com/topic/179879-solved-overload-constructor/ Share on other sites More sharing options...
Alex Posted November 1, 2009 Share Posted November 1, 2009 Yes, that's the correct way to call a parents constructor. Quote Link to comment https://forums.phpfreaks.com/topic/179879-solved-overload-constructor/#findComment-948941 Share on other sites More sharing options...
hkothari Posted November 1, 2009 Author Share Posted November 1, 2009 Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/179879-solved-overload-constructor/#findComment-948942 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.