This article mainly introduces the extension and inheritance usage of php classes, and analyzes in detail the inheritance and extension operation skills of php classes in the form of instances, for more information about extensions and inheritance of php classes, see the examples in this article. 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.