1. Inheritance keyword: extends
The inheritance of the PHP class can be understood as sharing the contents of the inherited class. PHP use extends single inheritance method, please avoid! (non-C + + multiple inheritance) The inherited class is called the parent class (the base class) where the inheritors become subclasses (derived classes).
2. Rules for PHP inheritance
CLASS1------>CLASS2------>CLASS3
Inherited in turn, Class3 has Class1, class2 so functions and attributes to avoid the name of the method and attribute .
Class son{} inherits Class root{};
Class Son extends root{};
3. Base class method overloading and parent class method access
Because it belongs to the principle of down inheritance, the base class cannot use the contents of the derived class, and some methods of this time base class cannot accomplish the function of some of our derived classes, we can do the method overloading to avoid the confusion of the new method.
Method overloading We can also understand method overrides, which are overloaded with method names that have the same name as the base class method in a derived class.
Overload when we need to call the original base class content, and then add new content, we can use
Base class Name:: Method name.
Instance:
<?PHPclassroot{function Dayin () {return "Root print <br/>"; }} classSon extends root{function Dayin () {//return $this->dayin (). " Son print <br/> "; returnRoot::d ayin ()."Son print <br/>"; }} $s=NewSon (); Echo $s-Dayin ();?>