What is Singleton Design Pattern in PHP?
It is basically used to restrict the class instantiation to a single object. It may be useful in those cases if only one object needs throughout the system. They are designed to ensure there is s single instance of a class which is the global point of access to it. We have also lazy initialization as well as global access along with single instance.
Objective – The main objective of singleton design pattern is to ensure that it has only one class instance as well as provide a global point of access to retrieve it.
Things to Know About Singleton Pattern
Usage of Singleton Pattern
Singleton Pattern Anatomy in PHP Context
The following conditions which you need to fulfill
Singleton as Anti-Pattern
By many developers, singleton design pattern is considered as Anti-pattern. Now question arise what basically Anti-pattern is? – They are basically design solutions which are usually ineffective as well as present a high risk of being counterproductive.
In spite of many advantages, it has some flaws but there is some uniqueness which makes singleton design pattern apart from others.