Home > php教程 > php手册 > PHP object-oriented - introduction to access modifiers_php basics

PHP object-oriented - introduction to access modifiers_php basics

WBOY
Release: 2016-05-16 09:00:20
Original
2291 people have browsed it

There are three access modifiers in PHP, which are:

public (public, default)
protected (protected)
private (private)

They can be used separately Used on the attributes and methods of a class (the attributes and methods of a class are collectively called members of a class) to modify the access permissions of class members.
public (public, default)
In PHP5, if a class does not specify an access modifier for a member, the default is public access.

/*
The following two methods have the same effect of declaring access permissions
*/
function say(){};
publilc function say(){};
When a member of a class is declared with a public access modifier, the member can be accessed and operated by external code.
private (private)
Members defined as private are visible to all members within the class and have no access restrictions. Access is not allowed outside the class.
protected (protected)
protected is a little more complicated. It is declared as a protected member and only allows access by subclasses of this class.

Access permission status table:

Access rights

public

protected

private

All

Subclass

Within class

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template