Before saying that each time you create a new object, the __construct method is executed first, then when inheriting, do you first execute the _construct method of the parent class and then execute the subclass __construct method?
Let's do an experiment:
classFather{publicfunction__construct(){echo"father has constructed"; }}classChild{publicfunction__construct(){echo"child has constructed"; }}$cnew Child();
The output results are as follows:
Child have constructed
Explains that the __construct method of the parent class was not called when the subclass was created, which is why this is a mechanism for rewriting (overwrite) in PHP, where the constructor of a subclass actually overrides the constructor of the parent class. The constructor for the subclass is executed.
So what happens if the subclass doesn't write the __construct method? Let's experiment:
classFather{publicfunction__construct(){echo"father has constructed"; }}classChild{publicfunctionshow(){echo"dd"; }}$cnew Child();$c->show();输出结果为:dd
;
The output is: DD
Indicates that the __construct () of the parent class is not inherited.
'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
'). Text (i)); }; $numbering. FadeIn (1700); }); });
The above describes the PHP learning notes Object-oriented (iv) Inheritance supplement, including aspects of the content, I hope to be interested in PHP tutorial friends helpful.