<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>多态性</title> </head> <body> <?php abstract class Car{ //注意类名和函数名都要加abstract abstract public function say(); } class Taxi extends Car{ public function say(){ echo "出租车"."<br>"; } } class Bus extends Car{ public function say(){ echo "公交车"."<br>"; } } function say($obj ){ if($obj instanceof Car){ $obj->say(); } } $taxi=new Taxi(); $bus=new Bus(); say($taxi); //输出"出租车" say($bus); //输出"公交车" ?> </body> </html>