对php多态的理解:
/** * 定义接口 */ interface Shape{ public function draw(); } /** * 三角形 */ class Triangle implements Shape{ public function draw(){ echo "This is Triangle"; } } /** * 矩形 */ class Rectangle implements Shape{ public function draw(){ echo "This is Rectangle"; } } class TestPoly{ public function drawNow($shap){ $shap->draw(); } } $test = new TestPoly(); $test->drawNow(new Triangle); echo '<br />'; $test->drawNow(new Rectangle);