Singleton pattern: Simply put, an object is only responsible for one specific task.
Singleton class:
1. The constructor needs to be marked as private. The singleton class cannot be instantiated in other classes, but can only be instantiated by itself
2. Have a Save the instance static member variables of the class
3. Have a public static method to access this instance. [The getInstance() method is commonly used to instantiate singleton classes, and the instanceof operator can be used to detect whether this class has been instantiated]
Note: You need to create a __clone() method to prevent the object from being copied
Function:
1. PHP applications are mainly used for databases, so there will be a large number of database operations in an application. Using singleton mode can avoid a large number of resources consumed by new operations
2. If a class is needed in the system to globally control certain configuration information, it can be easily implemented using the singleton mode. Refer to the FrontController section of ZF
3. Request summary on one page for easy debugging, because all the code is concentrated in one class, we can set hooks in the class and output logs, thus avoiding var_dump and echo everywhere.