interface 和 implements
使用interface代替class建立接口,接口中成员必须是常量,方法是抽象方法,并且不必加abstract
- interface demo {
- const NAME="我叫MT";
- function ji();
- function ji2();
- }
使用implements 引用接口,单继承,多接口,先继承后接口
- <?
- interface demo {
- const NAME="我叫MT";
- function ji();
- function ji2();
- }
- interface demo2 {
- function ji3();
- function ji4();
- }
- interface demo3 {
- function digg();
- }
- class Myclass implements demo,demo2{
- public $ji;
- public $ji2;
- public $date;
- public $adress;
- public $digg;
- function __construct($ji,$ji2,$date,$adress,$digg){
- $this->ji =$ji;
- $this->ji2 = $ji2;
- $this->jidate= $date;
- $this->adress = $adress;
- $this->digg = $digg;
- }
- function ji(){
- return self::NAME."这是第".$this->ji."季";
- }
- function ji2(){
- return $this->ji()."第".$this->ji2."集";
- }
- function ji3(){
- return "出品时间".$this->jidate;
- }
- function ji4(){
- return $this->ji3()."出处网站".$this->adress;
- }
- }
- class Quan extends Myclass implements demo3 {
- function digg(){
- return $this->ji2()."<br>".$this->ji4()."<br>关注度为".$this->digg;
- }
- }
- $myclass = new Quan(4,2,date('Y-m-d'),"youku",1251);
- echo $myclass->digg();
- ?>
输出结果
我叫MT这是第4季第2集
出品时间2011-09-30出处网站youku关注度为1251