PHP 设计模式-单例模式

实例化一次

单例模式无法new $db = new Database();
单例模式-> $db = Database::getInstance();
Database.php

class Database{
    protected $db;

    private function __construct(){

    }

    static function getInstance(){
        if(self::$db){
            return self::$db;
        }else{
            self::$db = new self();
            return self::$db;
        }
    }

    function where($where){
        return $this;
    }

    function limit($limit){
        return $this;
    }

    function order($order){
        return $this;
    }
}

你可能感兴趣的:(PHP 设计模式-单例模式)