Public: Common property or method
Can be called by Self::var or Self::method in a subclass, you can invoke a method in the parent class by Parent::method, but you cannot call the public property.
You can invoke the $obj->var or Self::method in the instance.
Protected: Protected Type
Can be called through Self::var or Self::method in a subclass, you can call methods in the parent class by Parent::method
Methods or properties of the protected type cannot be called through $obj->var in an instance
Private: Proprietary type
A property or method of that type can only be used in that class, and the properties and methods of private types cannot be called in instances, subclasses, or instances of subclasses of that class
The difference between 2.self and parent
A). These two objects are commonly used in subclasses. The main difference is that self can invoke a public or protected property in the parent class, but parent cannot call
b). Self:: It indicates that static members (methods and properties) of the current class are different from $this, $this refers to the current object
<?phpclass BaseClass {Public $public = ' public '; Private $private = ' private '; Protected $protected = ' protected '; function construct () {} function Print_var () {print $this->public;echo ' <br/> '; Print $this->private; echo ' <br/> '; Print $this->protected; echo ' <br/> '; }}class Subclass extends BaseClass {//Public $public = ' public2 '; protected $protected = ' protected2 '; function construct () {echo $this->protected;//can be accessed because the class is defined as protected, so in this class or subclass, you can also repeat the value in the subclass Echo ' <br/> '; Echo $this->private;//error because it is private only in defining her class BaseClass can be used}} $obj 1 = new BaseClass (); $obj 1->print_var (); Echo $obj 1->protected;//error because it is protected, only in this class inside or in the subclass parent class can call//echo $obj 1->private;//error as private, only within this class call Echo $ obj1->public; echo "
Summarize
Public represents the global, and the inner and outer subclasses of the class can be accessed;
Private means that only this class can be used internally;
Protected is protected and is accessible only in this class or subclass or in the parent class;