Extensions and inheritance usages of PHP classes _php tips

Source: Internet
Author: User
Tags php class php programming

The examples in this article describe the extension and inheritance usage of PHP classes. Share to everyone for your reference. as follows:

 <?php class Thread {var $topic;//Post theme var $body;//post content var $date;//Post release Time Var $author; Post author//function thread for initializing variable function thread () {//initialization variable}//function Send to submit new post function send () {/ /detection of the legality of variables after the insert operation to store variables in the database}//function edit to edit post function edit () {///check the legality of variables to perform an update operation to store variables in the database}//Function Del Ete is used to remove the Post function Delete () {//To detect the author's permissions will remove related data from the database}} class Mainthread extends Thread {var $id; /post number Var $board; Post in the discussion area Var $allowreply; 
  Allow reply//constructor to initialize variable function mainthread ($id, $board, $allowreply) {//For initializing variable} function Send () {////Check the legality of a variable to perform an insert operation to store the variable in the database Parent::send ();//////////////////// Operation to store variables in the database Parent::edit (); The edit function for calling the base class} $th = new Thread; 
Creates a new object if ($th instanceof Thread)//If the object $th is a thread type, the output is yes echo "yes"; 
else echo "No"; ?> 

I hope this article will help you with your 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.