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

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

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

本文實例講述了php 多繼承的幾種常見實現(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ù)默認的行為,會引發(fā)一個方法不存在的致命錯誤
    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();

運行結(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 "接口繼承,要實現(xiàn)所有相關(guān)抽象方法!";
    echo "<br>";
  }
  function dancing($name){
    echo $name."正在跳舞!";
  }
}
$demo=new testC();
$demo->echostr();
$demo->dancing("模特");

運行結(jié)果:

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

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

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

相關(guān)文章

最新評論

吉林省| 桂东县| 洛川县| 策勒县| 安国市| 垣曲县| 左权县| 藁城市| 克东县| 郧西县| 定西市| 达孜县| 金秀| 大姚县| 集贤县| 工布江达县| 清新县| 泸定县| 吉木乃县| 兴和县| 松阳县| 泸溪县| 随州市| 高邑县| 鞍山市| 锡林郭勒盟| 桐乡市| 潼南县| 江安县| 靖安县| 武汉市| 双峰县| 潮州市| 龙游县| 泰顺县| 平乡县| 琼结县| 祁门县| 沐川县| 达拉特旗| 南宫市|