Home  >  Article  >  Backend Development  >  Detailed explanation of inheritance method examples of PHP constructor

Detailed explanation of inheritance method examples of PHP constructor

怪我咯
怪我咯Original
2017-07-06 09:53:131123browse

This article mainly introduces the inheritance method of phpconstructor. It analyzes examples and summarizes various common situations of constructor inheritance. Friends who need it can refer to it

The example in this article describes the inheritance method of PHP constructor. Share it with everyone for your reference. The details are as follows:

The first case: When the subclass does not define a constructor, it is inherited by default. Example:

name="小强";
 }
}
class B extends A{
 
}
$bb = new B();
?>

Output result: Xiaoqiang

Second case: If the subclass defines a constructor, it will not be inherited. Example:

name="小强";
 }
}
class B extends A{
 function construct(){
 echo "BBBBBB子类";
 }
}
$bb = new B();
?>

Output result: BBBBBB subclass

Third case: If you need to call the constructor of the parent class, you can use: parent::parent class Function or parent class name::parent class function.

The above is the detailed content of Detailed explanation of inheritance method examples of PHP constructor. 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