我有一个奇怪的问题,无法用$_POST
进入课堂,很奇怪,这是问题和错误?课堂很简单,只是为了演示。
if(isset($_POST['name']))
{
$name=$_POST['name'];
$email=$_POST['email'];
$comment=$_POST['comment'];
$komentar = new comments($name,$email,$comment);
$komentar->provera();
}
类别:
class comments
{
public function __construct($name, $email, $comment)
{
$this->name=$name;
$this->email=$email;
$this->comment=$comment;
}
public static function provera()
{
$poruka=$this->comment;
echo $poruka;
}
}
我收到了这个错误
Fatal error: Using $this when not in object context in
classes\comments.inc.php on line 12
答案 0 :(得分:5)
您不能在静态方法中使用$this
。除非您需要静态调用provera()
,否则请从其声明中删除static
关键字。