php - Using Static or Singleton ClassesGet the solution ↓↓↓
I am currently trying to learn about MVC pattern and developing a basic project.
From time to time I had to use some classes in many different sections in my project and I wanted to avoid creating static classes for them. While doing research on this subject, I came across the pattern named Singleton and wanted to use it.
Still, I found that Singleton wasn't a very good practice either. I understand why I should avoid using singleton and static classes. But I was wondering (and I've read almost all the questions on Stackoverflow on this topic, yet I haven't found a satisfactory answer) in any project that really doesn't have any Singletons and static classes, is it always better? I currently have 1 static class, and I use it to load other classes, it is a loader class. And this makes my job quite easy.
But when I read about it all the replies give me the vibe that Singleton and static classes are bad and should be avoided to the end. Should I avoid using it even in my loader class or would it be useful to use them in global parts like i18n or loading project libraries? I have probably been one of the thousands to ask this question but I really could not figure it out. Almost all popular PHP frameworks use static classes but many of you guys says "Static classes are evil." and "Singletons are bad.".
Share solution ↓
Link To Answer People are also looking for solutions of the problem: installation failed, reverting ./composer.json and ./composer.lock to their original content
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.