在php验证中解析错误

时间:2014-01-08 22:53:46

标签: php mysql compiler-errors

我一直在尝试让这段代码工作很长时间,我仍然遇到同样的错误。 任何帮助都会很棒。

错误代码

Parse error: syntax error, unexpected ';' in /home/ob219/public_html/membership/classes/Validate.php on line 38

<?php
class Validate {
private $_passed = false,
        $_errors = array(),
        $_db = null;

public function __construct() {
    $this->_db = DB::getInstance();
}

public function check($source, $items = array()) {
    foreach($items as $item => $rules) {
        foreach($rules as $rule => $rule_value) {

            $value = trim($source[$item]);
            $item = escape($item);

            if($rule == 'required' && empty($value)) {
                $this->addError("{$item} is required");
            } else if(!empty($value)) {
                switch($rule) {
                    case 'min':
                        if(strlen($value) < $rule_value) {
                            $this->addError("{$item} must be a minimum of {$rule_value} characters.");
                        }
                    break;
                    case 'max':
                        if(strlen($value) > $rule_value) {
                            $this->addError("{$item} must be a maximum of {$rule_value} characters.");
                        }
                    break;
                    case 'matches':
                        if($value != $source [$rule_value]) {
                            $this->addError("{$rule_value} must match {$item}");
                        }
                    break;
                    case 'unique':
                        $check = $this->_db->get($rule_value, array($item, '=', $value);
                            if($check->count()) {
                                $this->addError("{$item} already exists.");
                            }
                    break;


                }

            }

        }
    }

    if(empty($this->_errors)) {
        $this->_passed = true;
    }

    return $this;
}

private function addError($error) {
    $this->_errors[] = $error;
}

public function errors() {
    return $this->_errors;
}

public function passed() {
    return $this->_passed;
}
}

1 个答案:

答案 0 :(得分:4)

忘了关闭paranthesis。变化

$check = $this->_db->get($rule_value, array($item, '=', $value);

$check = $this->_db->get($rule_value, array($item, '=', $value));