调用类中的关联数组

时间:2014-04-08 22:26:05

标签: php arrays

非常确定这是一个简单的解决方案,我没有看到,但目前正在尝试创建一个简单的系统,在允许用户继续操作之前检查用户的用户名和密码输入。如果检查没有停止,则会显示一条错误消息,指出输入错误。我通过像这样的关联数组尝试这个:

  public function check() {
if (strlen($this->_username) < $this->_minimumChars) {
    $this->_error['idlength'] = "Username needs to be longer than $this->_minimumChars characters";
}
if (!preg_match('/^[a-zA-Z0-9]+$/', $this->_username)) {
    $this->_error['idformat'] = "Username can only contain letters and numbers";
}
if (strlen($this->_password) < $this->_minimumChars) {
    $this->_error['pwdlength'] = "Password must be longer than $this->_minimumChars characters";
}
if (empty($this->_error)) {
    return $this->_result = true;
} }

我已将$ _error变量作为protected $_error = array();

启动

我试图调用方法

  public function getError() {
return $this->_error; }

使用$errors = $checker->getError();其中$ checker是该类的实例。 但是,当我尝试使用$ errors数组时,似乎没有任何启动。我已尝试在条件语句中使用empty($errors['idlength'])对其进行故障排除,但似乎数组中没有元素。

谁能告诉我哪里出错?

0 个答案:

没有答案