What is the usage of private in php

WBOY
Release: 2023-03-15 13:22:01
Original
3859 people have browsed it

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  类名{
访问控制修饰符  属性或方法定义;
}
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template