PHP使用接口的好处之一
interface Isay {public function say();
}
class hello implements Isay{
public function say(){
echo "hello";
}
}
class world implements Isay{
public function say(){
echo "world";
}
}
function test_say(Isay $isay){
$isay->say();
}
test_say(new hello()); //output:"hello"
test_say(new world()); //output:"world"
页:
[1]