Jump to content

[SOLVED] Overload Constructor


hkothari

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.