Home >Backend Development >PHP Tutorial >Thoughts caused by protected in php

Thoughts caused by protected in php

不言
不言Original
2018-04-28 15:56:563332browse

This article mainly introduces the thoughts about protected in php. It has certain reference value. Now I share it with you. Friends in need can refer to it

protected: is protected Protected, it can only be used inside the class and inherited classes, and cannot be used outside the class. In other words, it is the use of $this-> or $parent::;

to call the parent class: variable in the subclass and parent class$this-> Variable name, if there is this variable in the subclass, the variable in the subclass will be called, if not, the variable in the parent class will be called ; Method call: $this->Method name();If there is this method in the subclass, the method in the subclass will be called. If not, the method in the parent class will be called.

parent:: in the class always calls the method in the parent class and does not call the attribute.


The above is the detailed content of Thoughts caused by protected 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