Why PHP finally makes you a (more) rigorous developer

Alexandre Daubois
4 min readJun 7, 2021

Recent evolution of PHP is making it more demanding, for the best of everybody.

Photo by Ben on Unsplash

Strict typing

Maybe one of the most important thing you should be using on newest versions of PHP.

There was a time you were allowed to pass any data to any variable, cast variables as much as you wish, without any way to prevent this. Converting an array variable to a string, a string to an integer, etc. That can be pretty confusing, and potentially a bug nest. What will happen if you multiply a string by an integer for example? Well, the result is totally unexpected. This isn’t well managed like Python, where these types of operations are allowed and pretty well controlled. If your PHP code relies on this ability of weak typing, there may be a problem with your code architecture.

PHP now allows to strictly type in some situation. At the time of writing this article, you can’t type a variable if it is not a class attribute. That said, you should definitely type all your attributes of your classes. Less confusion, more rigor. Because yes, you’ll definitely improve your rigor by doing so. You may have to rethink some parts of your code, but it’s for the better. For a cleaner, more understandable code.

--

--