草庐IT

echoExtendedStaticVariable

全部标签

php - PHP 5.3 之前的静态继承

classA{static$v="A";staticfunctionechoExtendedStaticVariable(){echoself::$v;}}classBextendsA{static$v="B";//overrideA'svariablewith"B"}为什么:echoB::$v打印“A”?我如何让它打印“B”?在PHP5.3之前有办法做到这一点吗? 最佳答案 B->echoExtendedStaticVariable()=='A'因为self::是在编译时计算的,而不是运行时.这就好像你写的是A::而不是self: