PHP静态延迟绑定简单示例

时间:2014-06-22 07:14:10   收藏:0   阅读:298

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

<?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



PHP静态延迟绑定简单示例,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!