<?php header("Content-type:text/html;charset=utf8"); interface employee { public function working(); } class teacher implements employee { public function working() { echo '教书'; } } class coder implements employee { public function working() { echo '敲代码'; } } function doprint(employee $i) { $i->working(); } $a = new teacher(); $b = new coder(); doprint($a); echo '<br>'; doprint($b);
echo '本方法需要重载才能运行'; } } class teacher extends employee { public function working() { echo '教书'; } } class coder extends employee { public function working() { echo '敲代码'; } } function doprint($obj) { if (get_class($obj) == 'employee') { echo 'Error'; } else { $obj->working(); } } doprint(new teacher()); echo '<br>'; doprint(new coder()); echo '<br>'; doprint(new employee());