echo "单件模式 控件PHP类的实例化次数"; class text { const name="text"; public static $havenew = false; public $name = "我被限制为只能实例化一次!"; protected static $o_self; private function __construct() { } public function __destruct() { self::$havenew = false; } public static function initer() { if(empty(self::$o_self)) self::$o_self = new self; else{ echo "类:".self::name."已经实例化!"; } return self::$o_self; } } $class = text::initer(); var_dump($class); echo "<BR><BR>"; $class2 = text::initer(); var_dump($class2); die();