Entry
How can I call an ancestor's constructor method?
Nov 15th, 2002 11:04
BD KR, Nathan Wallace, john martin, BDKR
In PHP a constructor is just a function with the same name as the
class
it is contained in. So, to call the constructor of a parent or
ancestor
class you just need to call the function with the name of that
class.
For example:
class A {
function A () {
// constructor
}
}
class B extends A {
function B () {
// constructor
this->A();
}
}
This can also be done per the example below.
class Jango
{
function Jango()
{ echo "I'm just a regular guy trying to make my
way in the Universe\n"; }
}
class Boba extends Jango
{
function Boba()
{ parent::Jango(); }
}
$jan = new Boba;