当前位置:Gxlcms > PHP教程 > PHP延迟静态绑定示例分享_PHP教程

PHP延迟静态绑定示例分享_PHP教程

时间:2021-07-01 10:21:17 帮助过:27人阅读

没怎么用过这个新特性,其实也不算新啦,试试吧,现在静态类的继承很方便了

<?php
class A {
 protected static $def = '123456';

 public static function test() {
  echo get_class(new static);
 }

 public static function test2() {
  echo static::$def;
 }
}

class B extends A {
 protected static $def = '456789';
}

class C extends A {
 protected static $def = 'abcdef';
}

echo B::test();
echo '
'; echo C::test(); echo '
'; echo B::test2(); echo '
'; echo C::test2(); echo '
'; echo A::test(); echo '
'; echo A::test2(); echo '
';

// 
输出结果 B C 456789 abcdef A 123456

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/825540.htmlTechArticle没怎么用过这个新特性,其实也不算新啦,试试吧,现在静态类的继承很方便了 phpclass A { protected static $def = '123456'; public static function test...

人气教程排行