watermark logo

Singleton Pattern - PHP Design Patterns

3 Views
sarada
sarada
03 Feb 2024

The singleton programming pattern solves the problem of when you need one, and only one instance of given class on your script. Although this essentially creates you a global variable, it can be very beneficial when you shouldnt have multiple instances of the same class. For example, you might not want more than one database object, since the connection goes to the same server, database, and everything else. The key to a singleton is having a private constructor that keeps your client code from instantiating the class at will. Instead, the class itself has a static, public method that creates and serves up a reference to a public, static instance variable that holds a reference to an instance of the class. Sounds confusing? Then check out the video. Its really not complicated at all.
<br>
<br>PHP Design Patterns #2
<br>
<br>Copyright (c) new Rodrigo Silveira

Show more

0 Comments Sort By

No comments found

Facebook Comments

Up next