Soroush Khosravi
Soroush Khosravi

Reputation: 190

Can I use two constructor method in PHP?

I have two php files: main.class.php form.class.php

in these files there are two class that have same name as their file name and class form extends from main class main class has a constructor How can I set a constructor method for class form?

Upvotes: 0

Views: 336

Answers (1)

Nanocom
Nanocom

Reputation: 3726

class Main
{
    private $foo;

    public function __construct($foo)
    {
        $this->foo = $foo;
    }
}

class Form extends Main
{
    private $bar;

    public function __construct($foo, $bar)
    {
        parent::__construct($foo);
        $this->bar = $bar;
    }
}

Upvotes: 2

Related Questions