Home > Backend Development > PHP Tutorial > Sample code for simple implementation of multiple inheritance in PHP5

Sample code for simple implementation of multiple inheritance in PHP5

PHP中文网
Release: 2023-02-28 19:18:01
Original
851 people have browsed it

By studying the PHP language, we can know that PHP4 cannot implement multiple inheritance. So what about PHP5? We conducted a test on PHP5 and found that the implementation method of multiple inheritance in PHP5 is very simple.

PHPUploadSpecific usage of class upload.php

How to use PHP Ajax to achieve refresh-free upload of images

Analysis of the specific use of PHP5destructor

Specific application of PHP5 magic function

The following is the specific code for PHP5 multiple inheritance: The output structure is

The above is a sample code to simply implement multiple inheritance in PHP5 For more related content, please pay attention to the PHP Chinese website (www.php.cn)!
<? 
//PHP5 接口 ---跟 JAVA一个鸟样~ 晕  
interface IFOne{  
 function getName();  
}  
interface IFTwo{  
 function getID();  
}  
//PHP 抽象类   
abstract class AbsClsOne{  
 var $name;  
 function setName($name){  
  $this->name=$name;  
 }  
}  
abstract class AbsClsTwo{  
 var $id;  
 function setID($id){  
  $this->id=$id;  
 }  
}  
//单继承 多实现  
class ExtendsMoreCls extends AbsClsOne implements IFOne,IFTwo{  
 var $id;  
 private static $priVar="private";  
 function construct(){//PHP5的 构造函数  
  self::$priVar="set private";  
  $this->id=0;   
 }   
 function destruct(){//释构函数  
  echo "ExtendsMoreCls destruct";  
 }  
 function getName(){  
  return $this->name;  
 }  
 function getID(){  
  return $this->id;  
 }  
 public static function clsStaticFunc(){  
  echo "static function";  
 }  
}  
 
$emc=new ExtendsMoreCls();  
$emc->setName("kj021320");  
echo $emc->getName();  
echo "<br>";   
echo $emc->getID();  
echo "<br>";  
ExtendsMoreCls::clsStaticFunc();//调用静态方法  
echo "<br>";  
?>
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template