By 18/02/2016 16 Comments

What Is Private Access Modifier In PHP?

  • Any function or variable which is prefixed with private access modifier in a class, that function/variable can only be accessed/available/visible inside that class and can not be accessed/called outside a class or in another classes.


 class Class_Test{
 // following variable has private access.
 private $Site_Name = "";
 // following function has private access.
 private function display_message(){
 return "Private function..available only in this class,is being called through public function.";
 public function get_private_func(){
 return $this->display_message();

 $class_test = new Class_Test();
 // Trying to call a private variable outside a class causes fatal error.
 // echo "Website: " . $class_test -> Site_Name . "<br>";
 // Trying to call a private function outside a class causes fatal error.
 // echo $class_test -> display_message();
 // Trying to call a private function outside a class by another public function. this is fine.
 echo $class_test -> get_private_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 .