News for hackers. Stuff that matters.
Re:New to PHP 5.4: Traits by pornel on Saturday November 20, 2010 @11:10AM (#1924685)
Singletons don't solve problem of global variables, they are global themselves.

They are global shared state than can be unexpectedly accessed from any place in the program.

Encapsulation provided by singletons makes them even more problematic than global variables. You can temporarily overwrite global variable, run function that uses it, and restore global value. Singletons can be designed to prevent that, which kills testability of code that uses singletons (e.g. when you need to replace global DB connection with mock object).

There are no comments on this comment yet.