我有一个我想在其中使用 $this 的方法,但我得到的只是: fatal error :不在对象上下文中使用 $this。
我怎样才能让它工作?
public static function userNameAvailibility()
{
$result = $this->getsomthin();
}
最佳答案
这是正确的方法
public static function userNameAvailibility()
{
$result = self::getsomthin();
}
静态方法使用 self::
而不是 $this->
。
参见: PHP Static Methods Tutorial 了解更多信息 :)
关于php - 在静态函数中使用 $this 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2286696/