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