<?php
header("content-type:text/html;charset=utf-8");
interface Drive{
public function back();
public function go();
}
class Car implements Drive{
public function go(){
echo "我开车往前走";
}
public function back(){
echo"我开车往回走";
}
}
class Bike implements Drive{
public function go(){
echo "我往前骑车";
}
public function back(){
echo "我往回骑车";
}
}
function goForward($obj){
if($obj instanceof Drive){
$obj->back();
}
}
$tool1=new Car();
$tool2=new Bike();
goForward($tool2);
?>