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