Lecture: Singletons in PHP - Why they are bad and how you can eliminate them from your applications


While Singletons have become a Pattern-Non-Grata over the years, you still find it surprisingly often in PHP applications and frameworks. This talk will explain what the Singleton pattern is, how it works in PHP and why you should avoid it in your application.

The talk will start with a short history of where the Singleton came from, what it's goals are and how it can be implemented in PHP. I will then go on to show which of the five SOLID object oriented design principles Singletons violate and how it affects maintainability and testability of an application. I will explain why Global State and Coupling will hurt you in the long term and why Singletons are not as unique in PHP as in, for instance, Java.

The remaining time will be spent on showing how the Inline Singleton refactoring can be used to eliminate Singletons from a codebase in favor of a Dependency Injection solution with Factories and Builders.


Day: 2011-08-20
Start time: 11:15
Duration: 01:00
Track: PHP


Click here to let us know how you liked this event.