PHP延迟静态绑定示例分享
没怎么用过这个新特性,其实也不算新啦,试试吧,现在静态类的继承很方便了
<?php
classA{
protectedstatic$def='123456';
publicstaticfunctiontest(){
echoget_class(newstatic);
}
publicstaticfunctiontest2(){
echostatic::$def;
}
}
classBextendsA{
protectedstatic$def='456789';
}
classCextendsA{
protectedstatic$def='abcdef';
}
echoB::test();
echo'<br>';
echoC::test();
echo'<br>';
echoB::test2();
echo'<br>';
echoC::test2();
echo'<br>';
echoA::test();
echo'<br>';
echoA::test2();
echo'<br>';
//输出结果 B C 456789 abcdef A 123456
热门推荐
10 感谢韩语老师祝福语简短
11 升职文案高级祝福语简短
12 花童结婚祝福语大全简短
13 向国庆送祝福语简短
14 什么寄语简短祝福语女生
15 客户回礼祝福语大全简短
16 女孩生日祝福语简短创意
17 家长回复节日祝福语简短
18 给外婆敬酒祝福语简短