【发布时间】:2020-02-15 02:30:42
【问题描述】:
我有类似如下代码的情况:
class ParentClass
{
public static $property = 'parentValue';
public static function doSomethingWithProperty() {
echo 'Method From Parent Class:' . self::$property . "\n";
}
}
class ChildClass extends ParentClass
{
public static $property = 'childValue';
}
echo "Directly: " . ChildClass::$property . "\n";
ChildClass::doSomethingWithProperty();
从 cli 运行它,我得到输出:
Directly: childValue
Method From Parent Class: parentValue
有没有办法从父类中定义的静态方法中检索子类中定义的静态属性?
【问题讨论】:
-
静态值不会在遗产中被覆盖。 stackoverflow.com/questions/532754/…
标签: php oop static php-7 static-methods