首页 > php框架 > 简单实现PHP5多重继承

简单实现PHP5多重继承

在通过对
以下为PHP5多重继承的具体代码:

  1. <? 
  2. //PHP5 接口 ---跟 JAVA一个鸟样~ 晕  
  3. interface IFOne{  
  4.  function getName();  
  5. }  
  6. interface IFTwo{  
  7.  function getID();  
  8. }  
  9. //PHP 抽象类   
  10. abstract class AbsClsOne{  
  11.  var $name;  
  12.  function setName($name){  
  13.   $this->name=$name;  
  14.  }  
  15. }  
  16. abstract class AbsClsTwo{  
  17.  var $id;  
  18.  function setID($id){  
  19.   $this->id=$id;  
  20.  }  
  21. }  
  22. //单继承 多实现  
  23. class ExtendsMoreCls extends AbsClsOne implements IFOne,IFTwo{  
  24.  var $id;  
  25.  private static $priVar=private;  
  26.  function __construct(){//PHP5的 构造函数  
  27.   self::$priVar=set private;  
  28.   $this->id=0;   
  29.  }   
  30.  function __destruct(){//释构函数  
  31.   echo ExtendsMoreCls destruct;  
  32.  }  
  33.  function getName(){  
  34.   return $this->name;  
  35.  }  
  36.  function getID(){  
  37.   return $this->id;  
  38.  }  
  39.  public static function clsStaticFunc(){  
  40.   echo static function;  
  41.  }  
  42. }  
  43.  
  44. $emc=new ExtendsMoreCls();  
  45. $emc->setName(kj021320);  
  46. echo $emc->getName();  
  47. echo <br>;   
  48. echo $emc->getID();  
  49. echo <br>;  
  50. ExtendsMoreCls::clsStaticFunc();//调用静态方法  
  51. echo <br>;  
  52. ?> 

输出的结构为

kj021320
0
static function
ExtendsMoreCls destruct

希望通过上面对PHP5多重继承的实现代码,能够对有需要的朋友有所帮助。


永久地址:http://www.phprm.com/frame/php1003587.html

转载随意~请带上教程地址吧^^

标签:none

发表留言