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? 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. 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. Link to comment https://forums.phpfreaks.com/topic/179879-solved-overload-constructor/#findComment-948942 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.