Press "Enter" to skip to content

子类重写父类static属性

如果子类希望使用自己的static属性而不是使用父类的这个属性则,父类调用时使用static 反之使用self

示例:

class A
{
protected static $webplat = 1;
public function funTest()
{
echo static::$webplat;
}
}

class B extends A
{
protected static $webplat = 2;

}

echo (new B())->funTest();//2
echo (new A())->funTest();//1

发表评论