Home >Backend Development >PHP Problem >How to call parent class method in php subclass

How to call parent class method in php subclass

王林
王林Original
2020-11-04 14:19:054389browse

php The method for a subclass to call the parent class method: [$this->Method name ()]. ​​If there is this method in the subclass, the method in the subclass is called. If not, then The method in the parent class is called.

How to call parent class method in php subclass

Method call:

(Learning video recommendation: java video tutorial)

$this->方法名();

If there is this method in the subclass, the method in the subclass is called, if not, the method in the parent class is called.

parent::

Always call the method in the parent class.

Variable calling:

$this->变量名;

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.

Related recommendations: php training

The above is the detailed content of How to call parent class method in php subclass. 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