By 18/02/2016 7 Comments

What Is Protected Access Modifier In PHP?

  • The protected access modifier is used in Inheritance principal.
  • Any function or variable prefixed with protected modifier can only be accessed within child/sub classes. In other words they can not be accessed outside the parent child classes relationship.


 class Class_Test{
 // following variable has protected access.
 protected $Site_Name = "";
 // following function has protected access.
 protected function display_message(){
 return "Protected function in parent/base class..available only in it's child/sub classes.";
 class Class_My_Test extends Class_Test{
 public function get_parent_protected_variable(){
 return $this->Site_Name;
 public function get_parent_protected_func(){
 return $this->display_message();
 $class_my_test = new Class_My_Test();
 echo "Website: " . $class_my_test->get_parent_protected_variable(). "<br>";
 echo $class_my_test->get_parent_protected_func(); 

Posted in: PHP, Solutions

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .