Definition: PHP inheritance is somewhat different from other pure object-oriented
(completely dominated by object-oriented thinking from the beginning of design) programming languages.
1.Inheritance
in PHP can only single inheritance
:That is, the subclass has only one parent class (Java
Only supports single inheritance, C
supports multiple inheritance)
<?php class Man{} class Woman{} class Ladyboy extends Man,Woman{} //PHP中错误,不允许继承多个父类 ?>
2. If PHP wants to inherit multiple classes, you can use chain inheritance
<?php class Man{} class Woman extends Man{} class Ladyboy extends Woman{} //Ladyboy包含了Man和Woman类中所有可继承的成员 ?>
3. In PHP, only private methods
cannot be inherited (private properties can be inherited, but cannot be accessed)
4.PHP allows subclasses to inherit the constructor and destructor methods of the parent class
Recommendation:php tutorial,php video introductory tutorial
The above is the detailed content of Count the various aspects of life inherited by PHP. For more information, please follow other related articles on the PHP Chinese website!