Click to See Complete Forum and Search --> : inheritance hierarchy question


Jasp182
05-05-2007, 05:18 PM
This question has to deal with class inheritance greater than 2 levels. Consider you have the following:

class A
{
function doSomething() { echo "I'm in class A"; }
}

class B extends A
{
function doSomething() { echo "I'm in class B"; }
}

class C extends B
{
// doSomething is not declared
}

which parent class gets called when I call the following :

$c = new C();
$c->doSomething();

Piranha
05-05-2007, 05:34 PM
Try it and you will see. You have already most of the code, so it would not be any problem to try.

WDPEjoe
05-07-2007, 07:02 PM
If a class does not define a method, it will look in the parent class for the definition. If it is not defined, it will look in the parent class' parent class. And so on and so forth...