1. 程式人生 > >php利用介面實現類的多重繼承

php利用介面實現類的多重繼承

//定義介面A

interface A{

        function getName();

    }

//定義介面B

    interface B{
        function getAddress();

    }

    class AA implements A{
        private $name='xuxu';
        public function getName(){
            echo $this->name;
        }
    }
    class BB implements B{
        private $address='河南省';
        public function getAddress(){
            return $this->address;
        }

    }

//Info及繼承class AA又繼承了介面B

    class Info extends AA implements B{
        private $person;
        public function __construct(){
            $this->person=new BB();
        }
        public function getAddress(){
            echo $this->person->getAddress();
        }

    }
    $infos=new Info();
    $infos->getName();
    $infos->getAddress();