class ParentClass
{
private function foo()
{
echo 'foo() in ParentClass';
}
public function test()
{
echo $this::class; // ChildClass
$this->foo();
}
}
class ChildClass extends ParentClass
{
private function foo()
{
echo 'foo() in ChildClass';
}
}
$o = new ChildClass();
$o->test(); // 'foo() in ParentClass';
I expect the result is 'foo() in ChildClass'.
My question is why $this->foo();
inside test()
call foo()
in ParentClass rather in ChildClass? Why it is not get overriden?