2012-07-29 111 views
0

我有一個奇怪的問題,無法在類中輸入$_POST,很奇怪,這裏是問題和錯誤?類僅僅用於演示。類中的奇怪錯誤對象PHP

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 

回答

5

不能在靜態方法使用$this。除非您需要靜態調用provera(),否則請從其聲明中刪除static關鍵字。