这是我的代码:
class {
$property = "something";
public static function myfunc() {
return $this->property;
}
}
但是PHP会抛出以下错误:
在非对象上下文中使用$this
我知道,问题出在静态方法中使用了$this->
,好的,我会将其移除,像这样:
class {
$property = "something";
public static function myfunc() {
return self::property;
}
}
但是遗憾的是,PHP 抛出了以下错误:
未定义类常量 'property'
我该如何在一个静态方法之外访问属性?