I was playing around with late static bindings in a non static context and noticed that the class in which a function is called is dependent on the visibility. Below I have added two scenario's where the only difference is the visibility of the foo() function in class A. This determines whether the output is A or B. Could someone explain me what the reasoning behind this or where I can find more documentation on this?
/**
* Scenario 1
**/
class A {
private function foo() {
echo "A\n";
}
public function test() {
$this->foo();
}
}
class B extends A {
public function foo() {
echo "B\n";
}
}
$b = new B;
$b->test(); //returns A
/**
* Scenario 2
**/
class A {
public function foo() {
echo "A\n";
}
public function test() {
$this->foo();
}
}
class B extends A {
public function foo() {
echo "B\n";
}
}
$b = new B;
$b->test(); //returns B