Benedikt Schmitz
Benedikt Schmitz

Reputation: 3

How do you call constructor via child class?

I need to call the constructor of the following class Foto

class Foto extends Galerie
{
    function __construct($a,$b)
    { }
}

via its child class. Something like:

class Album extends Foto
{
    function __construct($a,$b)
    { return $this->Foto[__construct] }
}

Any ideas? Hope you'll get my point.

Upvotes: 0

Views: 101

Answers (2)

PeeHaa
PeeHaa

Reputation: 72729

You can call the parent constructor by doing:

parent::__construct($a, $b);

Now that we got that out of the way:

Please give your variables decent names. $a and $b tells nothing. Also I'm really wondering whether you should really extend those classes. Read about the Liskov substitution principle.

Upvotes: 1

andro1d
andro1d

Reputation: 568

parent::__construct($a,$b)

Is what you're looking for. You can also call parent class methods utilizing the same keyword.

Upvotes: 4

Related Questions