Properties and methods marked as protected are accessible only through the object that owns them : protected « Class « PHP






Properties and methods marked as protected are accessible only through the object that owns them

 
<?
    class Dog {
            public $Name;
            private function getName( ) {
                    return $this->Name;
            }
    }

    class Poodle extends Dog {
            public function bark( ) {
                    print "'Woof', says " . $this->getName( );
            }
    }

    $poppy = new Poodle;
    $poppy->Name = "Poppy";
    $poppy->bark( );
?>
  
  








Related examples in the same category

1.protected member variable
2.Class members' visibility
3.Class using access control
4.Private and protected variables