There are three types of access modifiers in PHP, respectively:
Public (common, default)
Protected (Protected)
Private (privately)
Public (common, default) in PHP5 if the class does not have an access modifier for the specified member, the default is the access permission for the.
protected (protected) is declared as a member of the protected, allowing access only to subclasses of that class.
Private is defined as a member of private, and is visible to all members within the class, without access restrictions. Access is not allowed outside of the class.
Graphic
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/PHP/
Demo
Class woman{Public $name = "Gaojin";
protected $age = "22";
Private $height = "170";
function info () {echo $this->name;
Private function Say () {echo "This is a private method";
}//$w = new Woman ();
echo $w->info ();
echo $w->name;//Public properties can access//echo $w->age;//protected Properties, report fatal error//echo $w->height;//protected Property, Report fatal error//private method, access error $w->say (); Private method, access error class Girl extends woman{//can redefine the public and protected methods of the parent class, but cannot define private//protected $na me = "Jingao";
You can define a new function info () {echo $this->name;
Echo $this->age;
Echo $this->height;
function say () {//parent::say ();//Private method cannot be inherited if the say method of the parent class is protected there is no error echo "I am a Girl";
}} $g = new Girl (); $g->say ()//Normal output//echo $g->height;//Private property access does not have output//$g->info ();//This is output gaojin22 $height is private property not inherited//$g ->height = "12";//This is the redefinition of the Height property is also assigned to//$g->info ();/So this will be output gaojin2212