Scout APM helps PHP developers pinpoint N+1 queries, memory leaks & more so you can troubleshoot fast & get back to coding faster. Start your free 14-day trial today.

Uncertainty, doubt, and static analysis

PHP is a strange language when it comes to type systems and static analysis. Back when it was created, it was a very dynamic and weakly typed language, but it has been slowly evolving towards a language with a stricter type system — albeit opt-in. Developers can still write dynamic and untyped PHP code if they want to, but more and more people seem to lean towards using PHP's type system regularly.

You can see this trend all throughout the community:

While I think this is a good evolution, I also realise there is a large group within the PHP community that don't want to use a stricter type system or rely on static analysis.

I've had several discussions with that group over the years, and it seems that we cannot get on the same page. I lay out my arguments in favour of stricter type systems and static analysis and as a response I get something like this: sure, but it's way too verbose to write all those types, it makes my code too strict to my liking, and I don't get enough benefit from it.

So when working on my latest video about the problem with null, I came up with yet another way to phrase the argument, in hopes to convince some people to at least consider the possibility that types and static analysis — despite their overhead — can still benefit them.

So, here goes. Attempt number I-lost-count:

My main struggle with writing and maintaining code isn't with what patterns to use or which performance optimizations to apply, it isn't about clean code, project structure or what not; it is about uncertainty and doubt. Here's what that looks like:

It is those kinds of questions and doubts that I'm bothered by, and it is those kinds of questions that a static analyser answers for me — most of the time.

So no, using a stricter type system and relying on static analysis doesn't slow you down. It increases productivity tenfold, it takes away so much uncertainty and doubt, it's liberating, and I cannot code without it anymore.

Noticed a tpyo? You can submit a PR to fix it. If you want to stay up to date about what's happening on this blog, you can follow me on Twitter or subscribe to my newsletter: