PHP父类调用子类方法

  1. <?php
  2. /**
  3. * 父类调用子类方法 基类
  4. *
  5. */
  6. class Base
  7. {
  8. /**
  9. * 调用子类方法
  10. */
  11. function _run_action()
  12. {
  13. $action = "index";
  14. $this->$action();
  15. }
  16. }
  17. class DefaultApp extends Base
  18. {
  19. /**
  20. * 此方法将在父类中调用
  21. */
  22. function index()
  23. {
  24. echo "DefaultApp->index() invoked";
  25. }
  26. function Go(){
  27. //调用父类
  28. parent::_run_action();
  29. }
  30. }
  31. $default=new DefaultApp();
  32. $default->Go();
  33. //将显示DefaultApp->index() invoked
  34. ?>

版权声明:本文为博主原创文章,未经博主允许不得转载。