interface 和 implementside
使用interface代替class創建接口,接口中成員必須是常量,方法是抽象方法,而且沒必要加abstract網站
- interface demo {
- const NAME="我叫MT";
- function ji();
- function ji2();
- }
使用implements 引用接口,單繼承,多接口,先繼承後接口this
- <?
- 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();
- ?>
輸出結果spa
我叫MT這是第4季第2集
出品時間2011-09-30出處網站youku關注度爲1251繼承