Home >Backend Development >PHP Problem >What are the common attribute modifiers in php

What are the common attribute modifiers in php

王林
王林Original
2019-10-11 17:45:083609browse

What are the common attribute modifiers in php

Form:

class  类名{
访问控制修饰符  属性或方法定义;
}
有3个访问修饰符:

public: Public: accessible (used) everywhere.

protected: Protected: can only be accessed (used) within the class and in subclasses or parent classes of the class.

private: Private: can only be accessed (used) within the class.

Function:

is used to "limit" the "accessibility" of the members it modifies;

Accessibility:

It is the "validity" (legality) of using these two syntax forms in the code:

Object->Instance attribute or method;

Class:: Static property or method;

Access control modifier, you need to use the location of this syntax form to determine whether it is accessible.

There are 3 access locations (scopes):

Inside a certain class:

Inside a class that inherits a certain class:

External to a certain class:

Summary description:

1. Public modified members can be accessed anywhere;

2 , inside the class, you can access members at any level;

3. Public has the broadest accessibility; private has the narrowest accessibility; protected is in the middle;

Recommended tutorial : PHP video tutorial

The above is the detailed content of What are the common attribute modifiers 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