Is there any advantages of storing database connection in static member variable instead of non static one that is encapsulated in singleton pattern? I just want to make sure that there isn’t any before I implement.
Personally, I tend to create a single database object (usually based on or extending the MySQLi or PDO class), and pass it to the constructors of objects which need it. I guess I prefer the visibility that provides in the interface.
If you prefer to invoke it from within each class from a global source, then I suspect a static variable might be a bit more efficient than invoking a singleton object in each class that needs it, but that's only a guess.
@SrWebDeveloperJan 05.2010 — #Just wanted to comment that professional PHP developers should note singletons are not unit testable. Doing so violates "test independence", a fundamental requirement for unit testing via tools like PHPUnit and SimpleTest.
FYI for those who follow SDLC and life cycle testing.