Home  >  Article  >  Backend Development  >  What is the usage of private in php

What is the usage of private in php

WBOY
WBOYOriginal
2022-02-23 14:33:103680browse

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}".

What is the usage of private in php

The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.

What is the usage of private in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn