当我调用方法validate()
时,我得到了这个错误Parse
错误:语法错误,意外T_VARIABLE,期待第205行\ 04Task.php中的T_FUNCTION
class RegexValidationRule extends ValidationRule {
public $regex;
public $result;
public function validate() {
$this->result = preg_match( $this->regex, $this->field->get_value() );
}
}
class ValidEmailValidationRule extends RegexValidationRule {
protected $regex = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";
$this->validate();
}
答案 0 :(得分:0)
class ValidEmailValidationRule extends RegexValidationRule {
protected $regex = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";
public function __construct() {
$this->validate();
}
}
你不能在这样的类定义中间使用语句,它们必须在函数内部调用。