我在子类静态方法中访问父(非静态)属性时遇到问题。我试过这些如下:
class Parent
{
protected $nonStatic;
// Other methods and properties
}
class Child extends Parent
{
public static function staticFunc()
{
$test = $this->nonStatic; # Using $this when not in object context
$test = self::$nonStatic; # Access to undeclared static property
$test = parent::$nonStatic # Access to undeclared static property
}
}
我在stackoverflow中检查了类似的问题,但我没有得到任何有效的解决方案
PS抱歉错别字,上面的代码是一个虚拟示例