I have a tiny class of inserting payment record into database. below is given:
<?php
class pay{
public static function pay($user, $income, $type, $refid='--'){
mysql_query("INSERT INTO earn VALUES (NULL, '$user', '$income', '$refid', '$type', ".time().")");
}
}
?>
But browser gives the below fatal error..
Fatal error: Constructor pay::pay() cannot be static in F:\xampp\htdocs\new\sts\class.php on line 41
I am confused that why the error occurring.. please help me to understand.
If you have a method name that is the same as the name of the class, it is considered to be a constructor. Constructors cannot be static. You must either rename this class or method, or make the method not static and create an instance of the class when you want to use it.