The object-oriented (iv) Inheritance supplement of PHP's learning notes

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.