我不明白为什么这个方法总是返回 false。我正在检查输入的密码的长度。绝对超过5个字符。输入字段的名称是正确的。但它总是抛出异常throw new Exception("Password must contain at least 6 characters.");
。
方法:
public function checkPassword(){
if(strlen($this->post_data['register_password']) > 5){
}else{
throw new Exception("Password must contain at least 6 characters.");
}
}
调用:
if( isset($_POST['register-submit'])){
$error = '';
$register = new register($_POST, $dbh);
try {
if($register->checkUsername()){
if($register->checkPassword()){
}
}
} catch (Exception $e) {
$error .= '<span style="color:red;">' . $e->getMessage() . '</span>';
}
}
编辑:添加了更多的类
public $post_data = array();
private $dbh;
public function __construct($post_data, PDO $dbh){
$this->error = array();
$this->post_data = array_map('trim', $post_data);
$this->dbh = $dbh;
}