<?php
class
Uni{
static
private
$instance
;
private
$config
;
private
function
__construct(
$config
){
$this
-> config =
$config
;
echo
"我被实例化了"
;
}
private
function
__clone(){
}
static
public
function
getInstance(
$config
){
if
(!self::
$instance
instanceof
self) {
self::
$instance
=
new
self(
$config
);
}
return
self::
$instance
;
}
public
function
getName(){
echo
$this
-> config;
}
}
$db1
= Uni::getInstance(1);
$db1
-> getName();
echo
"<br>"
;
$db2
= Uni::getInstance(4);
$db2
-> getName();
?>