Http://www.phpweblog.net/young40/archive/2007/11/21/2365.html
Generally, there is a one-to-many relationship between a class and an object (an instance of a class). But in some cases, we only
An instance of a class is required. For example, the diversity of multiple instances will bring some uncontrollable factors, many
Second instantiation, is a kind of resource waste, reduces the efficiency; and if they are factory objects (factory
Object), to create other objects in the system, and so on. At this time, the better way to deal with the class is to
The case is singular: to ensure that this class generates at most one instance during the run (Singleton modulo
, or keep all instances consistent (Monostate mode).
Example of implementing Singleton mode in PHP :
!--
Code highlighting produced by Actipro Codehighlighter (freeware)
http://www. codehighlighter.com/
--> . php
class singleton
{
Private static $ Instance ;
&NBSP
private function __construct ()
{
&NBSP}
public Static function instance ()
{
if