PHP does not have many inherited features. We rarely use this feature even if it is a programming language that supports multiple inheritance. In most people's view, multi-inheritance is not a good design method. To add an extra attribute to a class, you don't necessarily use inheritance. Here I provide a way to simulate multiple inheritance for reference. This article mainly introduces the extension and inheritance usage of PHP class, and analyzes the inheritance and extended operation skills of PHP class in detail in the instance form, and needs friends to refer to the following
<?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";?