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

不言
Release: 2023-04-03 21:36:01
Original
2849 people have browsed it

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!

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