Home >Backend Development >PHP Tutorial >Simple difference comparison and usage introduction between Public&Private&Protect in php

Simple difference comparison and usage introduction between Public&Private&Protect in php

不言
不言Original
2018-08-22 16:14:512875browse

This article brings you a simple comparison and usage introduction between Public&Private&Protect in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

public [Public]

can be called by other classes and objects anywhere in the program (inside the class, outside the class). Subclasses can inherit and use all public members of the parent class.

Private [Private]

Variables and methods modified by private can only be called and modified inside the class where they are located, and cannot be accessed outside the class. Neither is possible in subclasses.

If called directly, an error will occur.

Protect [Protected]

Class members modified with protected can be called in this class and subclasses, but cannot be called elsewhere.

Related recommendations:

public, private, protected in php5

The difference between public, private, and protected in php class , and examples

The above is the detailed content of Simple difference comparison and usage introduction between Public&Private&Protect 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

Related articles

See more