我有一个抽象类,基本上它定义了一堆常量、变量、抽象方法和非抽象/常规方法。它的典型结构是这样的:
abstract class ClassName{
const CONSTANT_NAME = "test";
protected static $variable_1 = "value";
protected $variable_2 = "value_2";
protected $variable_3 = "value_3"
abstract function doSomething();
protected function doSomethingElse();
}
困境是当我扩展这个类时,需要访问我的子类中的受保护变量,例如:
public class ChildClassName extends ClassName{
public function accessParentClassMembers()
{
echo parent::$variable_1; // WORKS FINE
echo parent::$variable_2; // OBVIOUSLY DOESN'T WORK because it is not a static variable
}
}
问题是,我如何访问$variable_2,即子类如何访问抽象父类*成员变量*?