Daily PHP Single-instance mode implementation
The singleton mode, as the name implies, only requires only one instanced object, in the software design, the singleton mode is very common. Instantiated once, save a lot of resources, and the singleton mode to some extent can replace the introduction of global variables in the class caused by the bug. Because global variables bundle classes into a particular environment. The encapsulation is broken, and such classes are difficult to be universally used by other applications. Using singleton mode allows classes to be better organized and reused.
Let's take a look at the implementation of the singleton pattern in PHP
Calling code
$singleton = Singleton::getinstance (), $singleton 2 = singleton::getinstance (); Var_dump ($singleton = = = $singleton 2);
In the call code above, it will print true at the end, so that we can simply implement the singleton pattern.