Examples of extensions and inheritance usages of PHP classes, examples of PHP inheritance usages _php Tutorials

Source: Internet
Author: User

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 ...

  • 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.