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.