I have a parent class containing a function funcB() which I like to override with a better function by making just a few changes in this function. This function in the parent class makes a call to another private function in the same class.
Sample code:
class classA {
private function funcA() {
return "funcA called";
}
public function funcB() {
$result = $this->funcA();
return $result;
}
}
class ClassB extends ClassA {
public function funcB($a) {
//do some more stuff
$result = $this->funcA();
return $result;
}
}
I get a Fatal error, because I’m not allowed to make a call to the private parent::funcA() function from within ClassB. But the call must being made. How is this still possible?
Declare the
privatemethod asprotectedinstead.See the documentation about visibility: