标签:zhang str return name ons cti zha instance elf
<?php
class single{
static public $db;
private function __construct(){
};
static function getinstance(){
if(!self::$db)
self::$bd = new self();
return self::$db;
}
}
single::getinstance();
//demo 2
class pzhang{
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;
}
}
$adb = pzhang::getInstance(1);
$adb->getname();
//结果 我被实例化了1
?>
标签:zhang str return name ons cti zha instance elf
原文地址:https://www.cnblogs.com/isuansuan/p/9754528.html