Blogger Information
Blog 30
fans 0
comment 2
visits 29252
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP 后期静态绑定案例
司马青衫
Original
649 people have browsed it

PHP 后期静态绑定

  • static关键字
    • 用于修饰类成员为静态成员
    • 用于函数体内定义静态局部变量
    • 用于在继承范围内引用静态调用的类(后期静态绑定)
  1. <?php
  2. //使用self关键字测试
  3. namespace self_test;
  4. class cBase{
  5. public static $val = 'cBase';
  6. public static function ret(){
  7. return self::$val;
  8. }
  9. }
  10. class cSub extends cBase{
  11. public static $val = 'cSub';
  12. }
  13. echo (new cSub)->ret();
  14. echo '<hr>';
  15. //使用static关键字测试
  16. namespace static_test;
  17. class cBase{
  18. public static $val = 'cBase';
  19. public static function ret(){
  20. return static::$val;
  21. }
  22. }
  23. class cSub extends cBase{
  24. public static $val = 'cSub';
  25. }
  26. echo (new cSub)->ret();

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post