forked from shaxzodbek-uzb/boot-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlingleton.php
More file actions
41 lines (36 loc) · 781 Bytes
/
Copy pathSlingleton.php
File metadata and controls
41 lines (36 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
class DB {
protected static $instance;
function __clone(){
throw new Exception("You can't clone singleton object", 1);
}
protected $db_type;
public function setType(string $type)
{
$this->db_type = $type;
}
public function connect()
{
echo "Connected to $this->db_type server";
}
static public function getInstance()
{
if(!self::$instance){
self::$instance = new DB();
}
return self::$instance;
}
}
$db = DB::getInstance();
$db->setType('PostgreSQL');
$db2 = clone $db;
$db->setType('MongoDB');
var_dump($db);
var_dump($db2);
unset($db);
// $db = DB::getInstance();
// $db->setType('Mongo');
// var_dump($db);
//
// $db->connect();
// require './index.php';