Examples of extensions and inheritance usages of PHP classes, examples of PHP inheritance usages
The examples in this article describe the extension and inheritance usage of PHP classes. Share to everyone for your reference. Specific 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 variables such as function thread () { //Initialize variable } //function Send to submit new post function Send () { //detect the legality of a variable and perform an insert operation to store the variable in the database } function edit for editing post function edit () { //detect the legality of a variable after performing an update operation to store the variable in the database } //function Delete to delete a post function Delete () { ///detects the author's permissions will delete related data from the database }} class Mainthread extends Thread { var $id;//Post Number C25/>var $board; The post is in the discussion area var $allowreply;//whether the reply //constructor is allowed to initialize the variable function mainthread ($id, $board, $allowreply) { //used to initialize the variable } function Send () { //to detect the legality of the variable after performing the insert operation to store the variable in the database parent::send (); The Send function used to call the base class } functions Edit () { //detects the validity of the variable after performing an update operation to store the variable in the database parent::edit (); The edit function used to call the base class }} $th = new Thread; Create a new object if ($th instanceof thread)//If the object $th is of type thread, the output is Yes echo "yes"; else echo "No";?>
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/1019434.html www.bkjia.com true http://www.bkjia.com/PHPjc/1019434.html techarticle Examples of extensions and inheritance usages of PHP classes, examples of PHP inheritance usages describe the extension and inheritance usage of PHP classes. Share to everyone for your reference. The following: PHP class Thread ...