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.".
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.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.