Home >Backend Development >PHP Tutorial >PHP中父类与子类的晚期绑定/延迟绑定

PHP中父类与子类的晚期绑定/延迟绑定

WBOY
WBOYOriginal
2016-06-13 10:58:34976browse

PHP中父类与子类的后期绑定/延迟绑定

  1. /**** 
  2. 燕十八 公益PHP讲堂 
  3.  
  4. 论  坛: http://www.zixue.it 
  5. 微  博: http://weibo.com/Yshiba 
  6. YY频道: 88354001 
  7. ****/  
  8.   
  9.   
  10. /*** 
  11. ====笔记部分==== 
  12. 后期绑定/延迟绑定 
  13. ***/  
  14.   
  15.   
  16. class Human {  
  17.     public static function whoami() {  
  18.         echo '来自父类的whoami在执行
    '
    ;  
  19.     }  
  20.   
  21.     public static function say() {  
  22.         self::whoami(); // 子类内没有say方法,找到了父类这里  
  23.                         // 在这里的self 指的是 父类  
  24.     }  
  25.   
  26.     public static function say2() {  
  27.         static::whoami();    //  子类也没有say2方法,又找到父类这里  
  28.                              // 但是父类用static::whoami,  
  29.                              // 指调用你子类自己的whoami方法  
  30.     }  
  31. }  
  32.   
  33.   
  34. class Stu extends Human{  
  35.     /* 
  36.     public static function whoami () { 
  37.         echo '来自子类的whoami在执行
    ';
     
  38.     } 
  39.     */  
  40. }  
  41.   
  42.   
  43. Stu::say();  
  44.   
  45. Stu::say2();  
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn