Member-only story
Why I don’t like using static in PHP
In summary, I don’t like using static classes in PHP. In this article, I will try to explain why.
How did it start?
When I started coding, I worked on a legacy project. In this project, I saw a lot of static usage, and I started to associate it with older, less efficient code. That is the biggest problem that I saw in newbies in programming but like 3 years ago I was doing the same.
One day I had a chance to develop a new project from scratch. I decided on the project structure and the whole backend side. I knew it was a big responsibility because if I made a bad decision, I’d be the only one responsible for it in the future :).
So I did my best and asked developers whose experience and knowledge I trusted what they thought as I went.
They all said, “Don’t use static.”
“Don’t use static”
I asked why and started to research why static would be a problem. Some of my findings are deprecated problems, but I want to share what I found.
1. Static methods make classes tightly coupled
Let’s start with an example. I asked Chat GPT for this example.
class DatabaseManager {
public static function connect() {…