在通过对以下为PHP5多重继承的具体代码:
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><strong><font color="#006699"></font></strong></span><span> </span></span></li> <li class=""><span>//PHP5 接口 ---跟 JAVA一个鸟样~ 晕 </span></li> <li class="alt"><span>interface IFOne{ </span></li> <li class=""><span> function getName(); </span></li> <li class="alt"><span>} </span></li> <li class=""><span>interface IFTwo{ </span></li> <li class="alt"><span> function getID(); </span></li> <li class=""><span>} </span></li> <li class="alt"><span>//PHP 抽象类 </span></li> <li class=""><span>abstract class AbsClsOne{ </span></li> <li class="alt"><span> var $name; </span></li> <li class=""><span> function setName($name){ </span></li> <li class="alt"> <span> $this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span class="attribute"><font color="#ff0000">name</font></span><span>=$name; </span> </li> <li class=""><span> } </span></li> <li class="alt"><span>} </span></li> <li class=""><span>abstract class AbsClsTwo{ </span></li> <li class="alt"><span> var $id; </span></li> <li class=""><span> function setID($id){ </span></li> <li class="alt"> <span> $this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span class="attribute"><font color="#ff0000">id</font></span><span>=$id; </span> </li> <li class=""><span> } </span></li> <li class="alt"><span>} </span></li> <li class=""><span>//单继承 多实现 </span></li> <li class="alt"><span>class ExtendsMoreCls extends AbsClsOne implements IFOne,IFTwo{ </span></li> <li class=""><span> var $id; </span></li> <li class="alt"> <span> private static $</span><span class="attribute"><font color="#ff0000">priVar</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"private"</font></span><span>; </span> </li> <li class=""><span> function __construct(){//PHP5的 构造函数 </span></li> <li class="alt"> <span> self::$</span><span class="attribute"><font color="#ff0000">priVar</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"set private"</font></span><span>; </span> </li> <li class=""> <span> $this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span class="attribute"><font color="#ff0000">id</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">0</font></span><span>; </span> </li> <li class="alt"><span> } </span></li> <li class=""><span> function __destruct(){//释构函数 </span></li> <li class="alt"><span> echo "ExtendsMoreCls destruct"; </span></li> <li class=""><span> } </span></li> <li class="alt"><span> function getName(){ </span></li> <li class=""> <span> return $this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>name; </span> </li> <li class="alt"><span> } </span></li> <li class=""><span> function getID(){ </span></li> <li class="alt"> <span> return $this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>id; </span> </li> <li class=""><span> } </span></li> <li class="alt"><span> public static function clsStaticFunc(){ </span></li> <li class=""><span> echo "static function"; </span></li> <li class="alt"><span> } </span></li> <li class=""><span>} </span></li> <li class="alt"><span> </span></li> <li class=""> <span>$</span><span class="attribute"><font color="#ff0000">emc</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">new</font></span><span> ExtendsMoreCls(); </span> </li> <li class="alt"> <span>$emc-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>setName("kj021320"); </span> </li> <li class=""> <span>echo $emc-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>getName(); </span> </li> <li class="alt"> <span>echo "</span><strong><font color="#006699"><span class="tag"><span class="tag-name">br</span><span class="tag">></span></span></font></strong><span>"; </span> </li> <li class=""> <span>echo $emc-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>getID(); </span> </li> <li class="alt"> <span>echo "</span><strong><font color="#006699"><span class="tag"><span class="tag-name">br</span><span class="tag">></span></span></font></strong><span>"; </span> </li> <li class=""><span>ExtendsMoreCls::clsStaticFunc();//调用静态方法 </span></li> <li class="alt"> <span>echo "</span><strong><font color="#006699"><span class="tag"><span class="tag-name">br</span><span class="tag">></span></span></font></strong><span>"; </span> </li> <li class=""> <span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span> </li> </ol>
输出的结构为
kj021320
0
static function
ExtendsMoreCls destruct
希望通过上面对PHP5多重继承的实现代码,能够对有需要的朋友有所帮助。