无法从php中的一个类访问另一个类的方法


Can not access to the method of another class from a class in php

数据库的类是这样的

class DB {
    private static $_instance = null;
    private $_pdo ,
            $_query ,
            $_results, 
            $_error=false, 
            $_count=0;
    private function __construct() {
        try {
            $this->_pdo= new PDO('mysql:host=' . Config::get('mysql/host') . ';dbname=' . Config::get('mysql/db'),Config::get('mysql/username'),Config::get('mysql/password'));
            //echo 'connected';
        } catch (PDOException $e) {
            die($e->getMessage());
        }
        }
        public static function getInstance(){
            if (!isset(self::$_instance)) {
                self::$_instance = new DB();
            }
            return self::$_instance;
        }
         public function get($table,$where){
            return $this->action("select *",$table,$where);
        }
}

我还有另一个类需要使用DB类

class Validate {
    private $_passed = false,
            $_errors = array(),
            $_db     = null;
    public function _construct (){
        $this->_db = DB::getInstance();
    }
   public function check($source , $items = array()){
            $check = $this->_db->get($rule_value,array($item, '=',$value)); 
  }

我的问题是当我运行这个程序时,我得到了一个错误,像这样

在非对象上调用成员函数get()

什么是这个错误的原因,因为我已经有一个DB类的实例在我的构造函数。

您的Validate构造函数没有正确定义,因此没有被调用。

public function _construct (){

没有构造函数调用意味着$this->_dbcheck()方法中返回null。它应该有另一个下划线:

public function __construct() {
                ^