Home  >  Article  >  Backend Development  >  简单实现PHP5多重继承的示例代码

简单实现PHP5多重继承的示例代码

PHP中文网
PHP中文网Original
2017-03-31 15:23:51720browse

在通过对PHP语言的学习我们可以知道,PHP4是无法实现多重继承的。那么对于PHP5呢?我们对PHP5进行了一个测试,发现PHP5多重继承的实现方法非常简便。

PHP上传类upload.php的具体使用方法

如何运用PHP Ajax实现图片的无刷新上传

解析PHP5析构函数的具体使用方法

PHP5魔术函数的具体应用讲解

PHP mysqli如何连接MySQL数据库

以下为PHP5多重继承的具体代码:

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 "
"; echo $emc->getID(); echo "
"; ExtendsMoreCls::clsStaticFunc();//调用静态方法 echo "
"; ?>

输出的结构为

kj021320
0
static function
ExtendsMoreCls destruct

 以上就是简单实现PHP5多重继承的示例代码的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)!

Statement:
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