I have a strange problem, can not enter in class with $_POST
, very strange, here is the problem and error? Class is simple just for demonstration.
if(isset($_POST['name']))
{
$name=$_POST['name'];
$email=$_POST['email'];
$comment=$_POST['comment'];
$komentar = new comments($name,$email,$comment);
$komentar->provera();
}
Class:
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;
}
}
I got this error
Fatal error: Using $this when not in object context in
classes\comments.inc.php on line 12
You can't use $this
in a static method. Unless you need provera()
to be called statically, remove the static
keyword from its declaration.