Singleton

When designing web applications, it often makes sense conceptually and architecturally to allow access to one and only one instance of a particular class. The singleton pattern enables us to do this.
The singleton pattern is useful when we need to make sure we only have a single instance of a class for the entire request lifecycle in a web application. This typically occurs when we have global objects (such as a Configuration class) or a shared resource (such as an event queue).

Reference: www.phptherightway.com

PROJECT_ROOT/vendor/PHPluz/Singleton.php

Example:
PROJECT_ROOT/vendor/PHPluz/etc/examples/Singleton/SingletonDemo.php

Now let’s create a test to have some output.
PROJECT_ROOT/vendor/PHPluz/etc/examples/Singleton/index.php

Output from the code above:

Demo

Leave a Reply