Examples of extension and inheritance usage of php classes, and examples of php inheritance usage

Source: Internet
Author: User

Examples of extension and inheritance usage of php classes, and examples of php inheritance usage

This article describes the extension and inheritance usage of php classes. Share it with you for your reference. The details are as follows:

<? Php class Thread {var $ topic; // post topic var $ body; // post content var $ date; // post release time var $ author; // post author // function Thread is used to initialize function Thread () such as variables {// initialization variable} // function Send is used to submit new post function Send () {// check the validity of the variable and execute the insert operation to store the variable in the database} // function Edit is used to Edit the post function Edit () {// check the validity of the variable and execute the update operation to store the variable in the database} // Delete the function to Delete the post function Delete () {// after checking the authority of the author, the relevant data will be deleted from the database} class MainThread extends Thread {var $ id; // Post No. var $ board ;// Post discussion area var $ allowreply; // whether to allow reply // constructor, used to initialize the variable function MainThread ($ id, $ board, $ allowreply) {// used to initialize the variable} function Send () {// check the validity of the variable and execute the insert operation to store the variable in the database. parent: Send (); // call the Send function} function Edit () {// check the validity of the variable and perform the update operation to store the variable in the database. parent: Edit (); // call the basic class's Edit function }}$ th = new Thread; // create a new object if ($ th instanceof Thread) // if the object $ th is of the Thread type, the output is Yes echo "Yes"; else echo "No";?>

I hope this article will help you with php programming.

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.