A Fresh Look at PHP

July 20, 2020
By

I never have been an active PHP developer. I’ve worked with it on the occasions I’ve had to, like hacking WordPress, or for smaller quick and dirty projects, but had never seriously considered the language for anything beyond that.

I have been familiar with the language from the early days, even before it offered any object-oriented support. Perhaps because of that early exposure, I had always essentially discounted the language and not taken it particularly seriously. This could also be due to the fact that because the language is so common and easy to get started with, it attracts a lot of self-taught inexperienced folks, which leads to a lot of poorly designed and ugly code that no one wants to look at, leave alone touch.

However, having recently been helping with a fairly large PHP-based project, representing some 30,000 lines of code, I have to say I have some new found respect for the language, the interpreter technology, and the supporting tooling,

As I recently told a friend, it’s still easy to write bad PHP code, and as noted above, the language as a whole suffers from the amount of such code floating around along with the wide variability of information and quality of example code. However, it’s not hard to write decent PHP code now and produce software that is reasonably manageable and still performs well, especially with the performance boost of PHP 7.

With tools like PHPUnit and Mockery and such one can build code with unit tests. The tooling and the language is not the problem. The problem is “programmers need to stop sucking so much,” to quote a friend from at least 10 years ago. It is possible to write loosely coupled, well architected software that can more easily be modified and maintained with PHP. The major problem is that the majority of PHP developers don’t know any better. They’ve just never been exposed to SOLID patterns and don’t appreciate the value in it. Doing so is harder in the beginning but pays off with software that is much easier to maintain. Instead, what we often find in real life is PHP projects that start out simple tasty morsels and quickly become spaghetti in mud that are fragile and very difficult to refactor and maintain – they don’t taste very good.

In short, PHP doesn’t suck.

While PHP still wouldn’t be my first choice for a big project, the universe of projects I might consider it for certainly is bigger now, particularly because it’s so easy to deploy to a shared server LAMP environment for nearly free with none of the overhead of managing your own AWS or Google Cloud services. And even in that environment, it can scale pretty far.

As part of my recent revisiting of PHP, I built this small skeleton to test building RESTful APIs with PHP using the Lumen framework: https://github.com/mrblog/ya-lumen-restapi-skeleton

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Buy Me A Beer

css.php