PHP class inheritance and extended operation skills

Source: Internet
Author: User
This article mainly introduces the PHP class inherits and expands the operation skill, the interest friend's reference, hoped to be helpful to everybody.

This example describes the extension and inheritance usage of the PHP class, as follows:

<?php class Thread {var $topic;//Post topic var $body;//post content var $date;//Post release Inter-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 variable legitimacy After performing the insert operation, store the variable in the database}//function edit to edit post function edit () {///detect the legality of the variable after performing an update operation to store the variable in the database}//function Delete to delete post Func tion Delete () {///detects the author's permissions will remove relevant data from the database}} class Mainthread extends Thread {var $id;//Post number var $board;//Posts var $allowreply in the discussion area;     Whether to allow the reply//constructor to initialize the variable function mainthread ($id, $board, $allowreply) {//For initializing the variable} function Send () { After checking the legitimacy of a variable, perform an insert operation to store the variable in the database Parent::send (); The Send function used to call the base class} functions edit () {//to detect the legality of the variable after performing an update operation to store the variable in the database Parent::edit ();///To invoke the Edit function of 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";? 

Summary: the above is the entire content of this article, I hope to be able to help you learn.

Related recommendations:

PHP implementation of Chinese character verification code

Implementation techniques of PHP unordered tree

PHP Process Control and mathematical operations

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.