接口

接口 php

抽象類提供了具體實現的標準,而接口(interface)則是純粹的模板。 this

接口只能定義功能,而不能實現內容。 spa

接口用關鍵字interface聲明 code

接口能夠包含屬性和方法聲明,但方法體爲空。

<?php
interface Test
{
    public function write();

    public function say();
}
?>

一個類可使用implements關鍵字來實現某個接口

class T1 implements TestClass
{
    public function write()
    {
        echo 'this is the write function<br/>';
    }

    public function say()
    {
        echo 'this is the say function<br/>';
    }
}


一個類能夠實現多個接口,但只能繼承一個父類 繼承

多個接口實現的方法: 接口

class testClass implements t1,t2,t3,t4...
{
// 實現的方法
}

繼承並實現多個接口的方法:

extends在前,implements在後 it

class testClass extends tClass implements t1,t2,t3
{
// 實現的方法
}
相關文章
相關標籤/搜索