Home > Article > Backend Development > Thoughts caused by protected in php
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!