<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## 接口(interface) 接口的要點: * 接口是通過 `interface` 關鍵字來定義的; * 接口中的方法只能聲明調用方式,不能定義這些方法的具體實現; * 接口中定義的所有方法都必須是 `public`; ``` <?php interface iTemplate { public function setVar($name, $var); public function getHtml($tpl); } ?> ``` ### 接口的實現 * 使用 `implements` 操作符來實現接口; * 類中必須實現接口中定義的所有方法,否則會報一個致命錯誤; * 必須使用和接口中所定義的方法完全一致的方式,否則會導致致命錯誤; ``` <?php class Template implements iTemplate { private $vars = array(); public function setVar($name, $var) { $this->vars[$name] = $var; } public function getHtml($tpl) { foreach($this->vars as $name => $value) { $tpl = str_replace('{' . $name . '}', $value, $tpl); } return $tpl; } } ?> ``` ### 接口的繼承 ``` <?php interface a { public function foo(); } interface b { public function bar(); } interface c extends a, b { public function baz(); } ?> ``` ### 多接口的實現 * 實現多個接口時,用逗號來分隔多個接口的名稱; * 實現多個接口時,接口中的方法不能有重名; ``` <?php interface a { public function foo(); } interface b { public function bar(); } interface c extends a, b { public function baz(); } class d implements c { public function foo(){} public function bar(){} public function baz(){} } ?> ``` ### 常量的使用 接口常量和類常量的使用完全相同,但是不能被子類或子接口所覆蓋。 ``` <?php interface a { const b = 'Interface constant'; } echo a::b; /* --------- 錯誤寫法 --------- */ class b implements a { const b = 'Class constant'; } ?> ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看