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
posted on 2017-06-25 20:12 gavanwanggw 阅读(92) 评论(0) 收藏 举报
浙公网安备 33010602011771号