Reputation: 49
<?php
class A {
private function foo(){
echo 1;
}
public function test(){
$this->foo();
}
}
class B extends A{
public function foo(){
echo 0;
}
}
$b = new B();
echo $b->test();
Class B inherits from class A. Why does the output result in 1 instead of 0?
Upvotes: 2
Views: 59
Reputation: 650
Because private methods can't be overridden. So, when A.foo
is defined again in class B its scope is different and A.test
can only see A.foo
Upvotes: 3