未实例化PHP数组

未实例化PHP数组,php,Php,如果使用JavaScript变量声明,则应将其更改为 <?php class Validate{ private $_passed = false, $_errors = array(), $_db = null; public function __construct(){ $this->_db=DB::getInstance(); } public function check($

如果使用JavaScript变量声明,则应将其更改为

<?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 = $source[$item];

                if($rule == 'required' && empty($value)){
                    $this->addError("{$item} is required");
                }else
                {

                }

            }

        }
        if($this->$_errors){ # <-- line 27
            $this->$_passed=true;
        }
        else
        {
            $this->$_passed=false;
        }
    }

    private function addError($error){
        $this->$_errors[] = $error; # <-- line 37

    }
    public function errors(){
        return $this->$_errors;
    }
    public function passed(){
        return $this->$_passed;
    }
}
然后,将新项目分配给数组时,请删除
$

private $_passed = false;
private $_errors = array();
private $_db     = null;
变成

$this->$_errors[] = $error;

是否改用
array\u push
<代码>数组推送($this->$\u errors,$error)。我仍然得到未定义的变量
$this->_errors[] = $error;