说明
- 基础模式之一;指在整个应用中只有一个对象实例。典型使用为创建数据库连接。
- 代码说明:
<?php
class Single
{
static protected $_instance = null;
private function __construct($option)
{
//实例化
}
static public function getInstance(array $option)
{
if (!(self::$_instance instanceof self)) {
self::$_instance = new self($option);
}
return self::$_instance;
}
private function __clone()
{
trigger_error('Clone is not allow', E_USER_ERROR);
}
}