简单实现PHP5多重继承
在通过对
以下为PHP5多重继承的具体代码:
- <?
- //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>;
- ?>
输出的结构为
kj021320
0
static function
ExtendsMoreCls destruct
希望通过上面对PHP5多重继承的实现代码,能够对有需要的朋友有所帮助。
永久地址:http://www.phprm.com/frame/php1003587.html
转载随意~请带上教程地址吧^^