yuanqiao 发表于 2017-3-31 06:13:29

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]
查看完整版本: PHP使用接口的好处之一