这是我得到的错误。
解析错误:语法错误,意外T_VARIABLE,期待T_FUNCTION 在/home/students/000313753/public_html/10065/php/lab2/lab2.php上 第121行
我的班级
class validate
{
public $errorArray;
function userName($name)
{
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if(isset($name))
{
if(strlen($name) <= 5)
{
$this->$errorArray['name'] = 'The username must be 5 characters.';
}
}
else
{
$this->$errorArray['name'] = 'Username cannot be empty';
}
}
}
function validateEmail($email)
{
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$this->$errorArray['email'] = 'Wrong email format.';
}
}
}
function validateYear($year)
{
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (isset($year))
{
if ($year < 1000 || $year > 2100)
{
$this->$errorArray['year'] = 'Year must be a 4 digit number.';
}
}
else
{
$this->$errorArray['year'] = 'Year cannot be empty';
}
}
function validateProvinces($provinces)
{
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (isset($provinces))
{
if (empty($provinces))
{
$this->$errorArray['provinces'] = 'Please select one or more provinces';
}
}
}
}
function validateStatus($status)
{
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (isset($status))
{
if (empty($status))
{
$this->$errorArray['status'] = 'Please select one or more items from status';
}
}
}
}
}
//access class
$validation = new validate()
$validation->userName($_POST["name"]);
$validation->validateYear($_POST["year"]);
$validation->validateProvinces($_POST["provinces"]);
$validation->validateStatus($_POST["status"]);
$validation->validateEmail($_POST["email"]);
?>
我是初学者,我有一天时间尝试调试。请不要只修复我的代码,向我解释为什么我的代码不起作用。
提前感谢您的帮助。
答案 0 :(得分:2)
你在这里错过了一个结束分号:
$validation = new validate()
应该是:
$validation = new validate();
答案 1 :(得分:0)
您在 }
function validateYear()