the private function it doesn't work because is private and comes from the class B,and the protected function is not working the b->operation2() ;
I don't understand the ___construct() $this->operation();

class A {
    private function operation1(){
        echo "operation1 called";
        echo "<br/>";
    }
    protected function operation2(){
        echo "operation2 called";
        echo "<br/>";
    }
    public function operation3(){
        echo "operation3 called";
        echo "<br/>";
    }
}
class B extends A {
    function __construct(){
        /*$this->operation1();*/
        $this->operation2();
        $this->operation3();
    }
}
$b = new B;
/*$this->operation1();*/
/*$b->operation2();*/
$b->operation3();

they return function operation2 and 3 and $b->operation3();

    A private method is not visible outside the class. So class B doesn't have operation1
    A protected method is not visible outside the class or any of its descendants. B is a descendant of A so it does have operation2, but outside all of that the method still hidden.
    A public method is visible publically.
    https://www.php.net/manual/en/language.oop5.visibility.php

      Write a Reply...