php利用介面實現類的多重繼承
阿新 • • 發佈:2019-02-11
//定義介面A
interface A{
function getName();}
//定義介面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
private $person;
public function __construct(){
$this->person=new BB();
}
public function getAddress(){
echo $this->person->getAddress();
}
}
$infos=new Info();
$infos->getName();
$infos->getAddress();