【发布时间】:2011-03-11 08:16:12
【问题描述】:
<?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!
?>
那么最好的解决方法是什么?
【问题讨论】:
-
将 self::$c 替换为 static::$c
-
@Artefacto 谢谢,效果很好!
标签: php inheritance static