To put it bluntly, I think it is to improve code efficiency. Next I will introduce the inheritance. The inherited subclass of a class inherits all member variable methods of the parent class, including the constructor. when the subclass is instantiated, php queries the constructor in the subclass, if the subclass has its own constructor method, php will first call the method in the subclass; if the subclass does not exist, php will call the constructor in the parent class, which is what we call inheritance.
What is class inheritance?To put it bluntly, I think it is to improve code efficiency. Next I will introduce the inheritance.
Class inheritance
Subclass inherits all member variable methods of the parent class, including the constructor. when the subclass is instantiated, php queries the constructor in the subclass. if the subclass has its own constructor, php will first call the method in the subclass; if the subclass is not, php will call the constructor in the parent class, which is what we call inheritance.
The class is inherited by the keyword extends. syntax:
class A extends B{...}
A represents A subclass, and B represents A parent class.
Now that we understand the basic concepts, let's take a look at the inherited instance of the class.:
First, create a class with different methods:
Name = $ name; $ this-> price = $ price;} function ShowInfo () {echo "not displayed ";}} // subclass Playclass Play extends Lol {// defines the subclass and inherits from the parent class public $ type; // defines the variable public function _ construct ($ name, $ type) in the subclass) {$ this-> name = $ name; $ this-> type = $ type;} function ShowInfo () {if ($ this-> type = "mid ") {return $ this-> name. "will play this location";} else {return $ this-> name. "won't Play this location" ;}}// instantiate the object $ player = new Play ("faker", "mid"); echo $ player-> ShowInfo ();
The above is php object-oriented: the details of the class inheritance instance. For more information, see other related articles in the first PHP community!