You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
689 B

3 years ago
  1. <?php
  2. /**
  3. * 静态的作用是不用通过实例话,
  4. * 直接通过区域操作符:: 访问调用
  5. */
  6. class ClassA{
  7. //静态属性
  8. public static $varA="这是一个静态属性";
  9. //静态方法
  10. public static function fnA() {
  11. echo "这个一个静态方法".PHP_EOL;
  12. }
  13. //对比this->和self::
  14. public static function fnB(){
  15. // echo $this->$varA; //this要通过对象来使用
  16. echo self::$varA;
  17. }
  18. }
  19. //访问静态属性
  20. echo ClassA::$varA.PHP_EOL;
  21. //访问静态方法
  22. ClassA::fnA();
  23. //对比this->和self::
  24. ClassA::fnB();
  25. ?>