Private call in extended class?

I have a parent class containing the funcB () function, which I would like to override with a better function, with just a few changes to this function. This function in the parent class calls another private function in the same class.

Code example:

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 am not allowed to make a call to the private parent :: funcA () function from the ClassB class. But the call has to be made. How is this still possible?

+4
source share
1 answer

Declare the private method as protected .

See visibility documentation :

Class members declared public may be available worldwide. Access to elements declared protected can only be accessed within the class itself and the inherited and parent classes. Participants declared as private can only have access to the class that the member defines.

+11
source

Source: https://habr.com/ru/post/1344574/


All Articles