Home  >  Article  >  Backend Development  >  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

高洛峰
高洛峰Original
2016-12-12 09:31:352199browse

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. 】


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