<?php
class Base {
protected static $c = 'base';
public static function getC() {
return self::$c;
}
}
class Derived extends Base {
protected static $c = 'derived';
}
echo Base::getC(); // output "base"
echo Derived::getC(); // output "base", but I need "derived" here!
?>
那么最好的解决方法是什么?
最佳答案
解决此问题的最佳方法是升级到 PHP 5.3,其中 late static bindings可用。如果这不是一个选择,那么您将不得不重新设计您的类。
关于php - 在 PHP 中重写派生类中的静态成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3169993/