Home > Backend Development > PHP Tutorial > A brief discussion on the scope of access modifiers private, protected, and public in PHP

A brief discussion on the scope of access modifiers private, protected, and public in PHP

高洛峰
Release: 2023-03-03 13:10:01
Original
2241 people have browsed it

1. Private can only be used inside the class.

2. Protected can be used inside the class and inherited classes. It cannot be used outside the class [that is, the instantiated object cannot be called]

3. Public applies to all scopes.

4. When a subclass overrides a method in a parent class, the scope of the access modifier in the subclass must be greater than or equal to the parent class's [ Inheritance can only be carried forward, or at least remain unchanged. Don't lose things. 】


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