Home > Backend Development > PHP Tutorial > Count the various aspects of life inherited by PHP

Count the various aspects of life inherited by PHP

autoload
Release: 2023-04-09 19:18:02
Original
2623 people have browsed it

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 (JavaOnly supports single inheritance, C supports multiple inheritance)

<?php
class Man{}
class Woman{}
class Ladyboy extends Man,Woman{}	//PHP中错误,不允许继承多个父类
?>
Copy after login

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类中所有可继承的成员
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template