I have read a lot about singletons, most people agree that they are bad practice and to avoid them, any way possible. Most people say this because it's hard to debug apps that use them.
Now, creating a simple CMS, I tried a few approaches and they seem to me the best choice.
- Configuration data
That file is loaded on application start and I see no reason why I wouldn't use singleton pattern when calling config data throughout my application?
- Request data
Request data should store all info from php server variables (POST, GET, COOKIE) so it can be used to read and write (e.g.cookies) data using singleton throughout the application.
- Response buffer
I want to use response class (as singleton) that will hold all data that is rendered by my templates. So application can load all views render them one by one and store the echoed data in the response class, and at the end output entire document that is stored in response.
Questions for all examples: A) Is that really bad practice, and why? I see no evil here. B) Is there an alternative / better way?
Thanks!