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.   
  18. class DefaultApp extends Base  
  19. {  
  20.       
  21.     /** 
  22.      * 此方法将在父类中调用 
  23.      */  
  24.     function index()  
  25.         {  
  26.             echo "DefaultApp->index() invoked";  
  27.         }  
  28.           
  29.     function  Go(){  
  30.         //调用父类  
  31.         parent::_run_action();  
  32.     }  
  33. }  
  34.   
  35. $default=new DefaultApp();  
  36. $default->Go();  
  37. //将显示DefaultApp->index() invoked  
  38.   
  39. ?> 

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

posted @ 2014-11-12 12:13  一直向北  阅读(1335)  评论(0编辑  收藏  举报