gpt4 book ai didi

php - 在静态函数中使用 $this 失败

转载 作者:IT老高 更新时间:2023-10-28 12:01:54 24 4
gpt4 key购买 nike

我有一个我想在其中使用 $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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com