Home > Article > Backend Development > What is the usage of private in php
In PHP, private is an access modifier, used to limit the accessibility of modified members. It means "private", that is, it can only be accessed and used inside the class. Syntax For "class class name {private attribute or method definition}".
The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.
public means global, and can be accessed by subclasses inside and outside the class;
private means private, and can only be used within this class;
protected means protected and can only be accessed in this class or subclass or parent class;
Access control modifier
Form:
class 类名{ 访问控制修饰符 属性或方法定义; }
Their function is to "limit" the "accessibility" of the members they modify;
Accessibility:
is to use these two syntax forms in the code" Validity" (legality):
Object-> instance property or method;
Class:: static property or method;
Access control modifier, need to be combined Use the location of this syntax form to determine whether it is accessible.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What is the usage of private in php. For more information, please follow other related articles on the PHP Chinese website!