多态:把不同的对象赋给同一个引用,调用同一个引用执行不同功能。
<?php
interface wine{
public function ad();
}
class kouzi implements wine{
public function ad(){
echo '生活,离不开那口子';
}
}
class jinjiu implements wine{
public function ad(){
echo '劲酒虽好,可不要贪杯哦';
}
}
class qibaosan implements wine{
public function ad(){
echo '七宝山不是山,喝了都说好';
}
}
function test($obj){
if($obj instanceof wine){
$obj->ad();
echo '<br/>';
}else{
echo '对象错误'.'<br/>';
}
}
header('content-type:text/html;charset=utf-8');
test(new kouzi);
test(new jinjiu);
test(new qibaosan);
?>