婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁(yè) > 知識(shí)庫(kù) > php 多繼承的幾種常見實(shí)現(xiàn)方法示例

php 多繼承的幾種常見實(shí)現(xiàn)方法示例

熱門標(biāo)簽:高德地圖標(biāo)注店鋪收費(fèi)嗎 泊頭在哪里辦理400電話 電銷機(jī)器人沒(méi)有效果怎么樣 杭州語(yǔ)音電銷機(jī)器人 高德地圖標(biāo)注位置怎么標(biāo)注 欣思維地圖標(biāo)注 江西電銷機(jī)器人收費(fèi) 天潤(rùn)融通外呼系統(tǒng)好嗎 江門回?fù)芡夂粝到y(tǒng)

本文實(shí)例講述了php 多繼承的幾種常見實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:

class Parent1 {
  function method1() {}
  function method2() {}
}
class Parent2 {
  function method3() {}
  function method4() {}
}
class Child {
  protected $_parents = array();
  public function Child(array $parents=array()) {
    $this->_parents = $parents;
  }
  public function __call($method, $args) {
    // 從“父類"中查找方法
    foreach ($this->_parents as $p) {
      if (is_callable(array($p, $method))) {
        return call_user_func_array(array($p, $method), $args);
      }
    }
    // 恢復(fù)默認(rèn)的行為,會(huì)引發(fā)一個(gè)方法不存在的致命錯(cuò)誤
    return call_user_func_array(array($this, $method), $args);
  }
}
$obj = new Child(array(new Parent1(), new Parent2()));
print_r( array($obj) );die;
$obj->method1();
$obj->method3();

運(yùn)行結(jié)果:

Array
(
    [0] => Child Object
        (
            [_parents:protected] => Array
                (
                    [0] => Parent1 Object
                        (
                        )

                    [1] => Parent2 Object
                        (
                        )

                )

        )

)

interface testA{
  function echostr();
}
interface testB extends testA{
  function dancing($name);
}
class testC implements testB{
  function echostr(){
    echo "接口繼承,要實(shí)現(xiàn)所有相關(guān)抽象方法!";
    echo "br>";
  }
  function dancing($name){
    echo $name."正在跳舞!";
  }
}
$demo=new testC();
$demo->echostr();
$demo->dancing("模特");

運(yùn)行結(jié)果:

接口繼承,要實(shí)現(xiàn)所有相關(guān)抽象方法!
模特正在跳舞!

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《PHP數(shù)組(Array)操作技巧大全》、《PHP基本語(yǔ)法入門教程》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》及《php常見數(shù)據(jù)庫(kù)操作技巧匯總》

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

您可能感興趣的文章:
  • PHP Trait代碼復(fù)用類與多繼承實(shí)現(xiàn)方法詳解
  • PHP中的Trait 特性及作用
  • PHP中trait使用方法詳細(xì)介紹
  • PHP中Trait及其應(yīng)用詳解
  • 淺談PHP中的Trait使用方法
  • PHP中的traits簡(jiǎn)單使用實(shí)例
  • PHP中的traits實(shí)現(xiàn)代碼復(fù)用使用實(shí)例
  • PHP的Trait機(jī)制原理與用法分析
  • PHP接口多繼承及tarits實(shí)現(xiàn)多繼承效果的方法
  • PHP 使用 Trait 解決 PHP 單繼承問(wèn)題詳解

標(biāo)簽:大同 雙鴨山 江門 駐馬店 石嘴山 深圳 內(nèi)江

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《php 多繼承的幾種常見實(shí)現(xiàn)方法示例》,本文關(guān)鍵詞  php,多,繼承,的,幾種,常見,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《php 多繼承的幾種常見實(shí)現(xiàn)方法示例》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于php 多繼承的幾種常見實(shí)現(xiàn)方法示例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 中超| 南澳县| 湘潭县| 古交市| 会昌县| 阿尔山市| 巴林右旗| 肃南| 勐海县| 张家港市| 昌邑市| 汉源县| 鞍山市| 肇州县| 寻甸| 霍林郭勒市| 二连浩特市| 禄劝| 濮阳市| 亚东县| 内黄县| 沙田区| 屏南县| 扶余县| 东辽县| 南开区| 五大连池市| 东源县| 达尔| 盘锦市| 平凉市| 香港| 交口县| 屏南县| 东城区| 大邑县| 星子县| 安溪县| 读书| 忻州市| 民权县|