最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2019年11月18日 09:46:08   作者:ztblog  
這篇文章主要介紹了php 多繼承的幾種常見(jiàn)實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了兩種PHP實(shí)現(xiàn)多繼承的操作方法,需要的朋友可以參考下

本文實(shí)例講述了php 多繼承的幾種常見(jiàn)實(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常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總

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

相關(guān)文章

最新評(píng)論

汾阳市| 安仁县| 都昌县| 八宿县| 陇西县| 安庆市| 齐齐哈尔市| 黑河市| 花莲市| 海伦市| 大兴区| 曲靖市| 平顶山市| 澄迈县| 三穗县| 西林县| 肇庆市| 贡嘎县| 邯郸县| 酒泉市| 嘉鱼县| 资阳市| 运城市| 湟源县| 北京市| 辰溪县| 凌源市| 五华县| 巫山县| 龙游县| 南江县| 尤溪县| 隆德县| 锦屏县| 文化| 漳浦县| 开阳县| 右玉县| 福贡县| 图片| 苍南县|