- <?php
- /**
- * 父类调用子类方法 基类
- *
- */
- class Base
- {
- /**
- * 调用子类方法
- */
- function _run_action()
- {
- $action = "index";
- $this->$action();
- }
- }
- class DefaultApp extends Base
- {
- /**
- * 此方法将在父类中调用
- */
- function index()
- {
- echo "DefaultApp->index() invoked";
- }
- function Go(){
- //调用父类
- parent::_run_action();
- }
- }
- $default=new DefaultApp();
- $default->Go();
- //将显示DefaultApp->index() invoked
- ?>
PHP父类调用子类方法
最新推荐文章于 2021-04-07 04:42:25 发布