没怎么用过这个新特性,其实也不算新啦,试试吧,现在静态类的继承很方便了
<?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
如对本文有疑问, 点击进行留言回复!!
20.7.17 笔记算数运算符 复合运算符重载 比较运算重载 多态 设计原则 类的单一职责 依赖倒置 组合复用原则 里氏替换 迪米特法则 矩阵转置原理
网友评论