源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

PHP延迟静态绑定示例分享

  • 时间:2022-08-20 04:47 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:PHP延迟静态绑定示例分享
没怎么用过这个新特性,其实也不算新啦,试试吧,现在静态类的继承很方便了
<?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 '<br>';
echo C::test();
echo '<br>';
echo B::test2();
echo '<br>';
echo C::test2();
echo '<br>';
echo A::test();
echo '<br>';
echo A::test2();
echo '<br>';
// 输出结果
B
C
456789
abcdef
A
123456

  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部