Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use private in php

Shulou Source: shulou.com Published: 2022-06-01 12:50:15 09月30日 Update

This article will explain in detail how to use private in php. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

In PHP, private is an access modifier that restricts the accessibility of decorated members, meaning "private", that is, it can only be accessed and used within the class, and the syntax is "class class name {private property or method definition}".

This article operating environment: Windows10 system, PHP7.1 version, Dell G3 computer.

What is the use of private in php

Public represents the global, and all the internal and external subclasses of the class can access it.

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 class name {access control modifier property or method definition;}

Their role is to "limit" the accessibility of the members they modify.

Accessibility:

Is to use the "validity" (legitimacy) of these two forms of syntax in your code:

Object-> instance property or method

Class:: static property or method

Access control modifiers, which need to be combined with the location where the grammatical form is used to determine whether they are accessible.

This is the end of the article on "how to use private in php". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Properties methods forms articles syntax controls only subclasses members more class names private restricted good legal practical valid that is code location Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Information Shulou Tech Info Shulou Technology Xiaomi