【发布时间】:2013-05-01 18:58:58
【问题描述】:
这是我生成随机字符串的静态函数:
public static function generateCode($salt)
{
$this->generate = substr(hash('sha512', $salt), 0, 15);
return $this->generate;
}
我就是这样使用它的:
$this->insert->execute(array(
":username" => $username,
"generated_code" => self::generateCode($email)
));
我已经声明了财产:
protected $generate;
收到此错误:
Fatal error: Using $this when not in object context in C:\xampp\htdocs\drip\class\users.class.php on line 154
第 154 行:
$this->generate = substr(hash('sha512', $salt), 0, 15);
这是怎么回事?为什么它给我这个错误?
【问题讨论】:
-
$this在静态函数中不存在。它们只存在于类上下文中,没有对象实例
标签: php