Using PHP for Good — How It’s Not Great, and Why It Could Work for You
PHP has received so much hate over the years that today it is one of the most notorious programming languages on the planet, only partially due to how popular and prevalent it is (+70% of websites), but it can be a force for good.
There are many posts on how easy it is to make mistakes, how inconsistent the language has become, how detrimental its lack of hard data-type checks has been, and how the amount of dark magic in it makes it slow, unpredictable, and generally not fit for purpose for most use-cases. This eev.ee article is one of my favorites on the subject of why PHP is bad as a language.
It is worth mentioning that efforts have been made by companies such as Facebook to improve upon PHP (e.g. by creating Hack) into a compiled language and there are big frameworks that can be leveraged for more structure and confident coding. But the virtual machine used by Hack is also known to quite resource savvy.
Additionally, type hinting does exist in PHP, but it is very much optional and very often ignored by beginners and in online code samples.
Why is it bad for new programmers?
It is very easy to start using it incorrectly, go down the rabbit hole, learn all the wrong practices, hacks and tricks and as a consequence write quite terrible code and carry these habits into your career.
As a stark contrast comparison, Java enforces OOP and Haskel leaves you no choice but to learn functional programming while Scala is the brainchild of both.
In PHP all of these and more can be used simultaneously, its wiki page itself mentioning imperative, functional, object-oriented, procedural, and reflective. This is good if you want to go in with a style you already love and understand, but not as great if you want to learn programming in your forming years.
The language is not particularly great at any of these paradigms. While you can apply all of them, it is quite verbose and does not feature complete languages dedicated to their art.
If you are new to programming and currently learning PHP, the point is not to give up, but instead research software design patterns, and a language such as C++/Java, or similar, alongside it (one that is compiled and with type safety). This is to ensure you are learning best practices when it comes to programming in general and to take what PHP provides with a grain of salt, evolving your ability to compare it to other languages from the start.
Disclaimer: I love PHP
I use it almost weekly for quick prototypes or for a thin logic layer for a UI needed for a new project. I have however moved away from using it for business logic. Some of my PHP projects can be found on my GitHub including browser-based games.
Am I going to give up on PHP?
No. I am not planning on giving up on PHP any time soon and I think if you have some experience with it you may want to consider it too for your projects. This is mainly because to have used it for over ten years and it now has become part of my programming tool belt.
Should you learn PHP as a software engineer?
If you are an accomplished developer using other languages, and you are full-stack, then you already have experience with your favorite UI framework of choice at which you are proficient in setting up from scratch really quickly. In which case I personally do not see a reason for you to consider switching to PHP unless you’re transitioning into a role that requires it. If you want to learn a new UI technology for the web, the recommendation would still be to look outside of the PHP box unless it is part of your role to do so. Angular and React are my go-to choices, sometimes having them talk to a PHP backend, avoiding having PHP take care of generating the HTML structures.
Should you learn PHP because it’s everywhere?
From experience, learning PHP because it is widely present in the web eco-system is not good enough of a reason in this case.
It is not popular at all outside of web development, but it is popular enough in that category to bring it to the top lists of general programming languages. Mainly because of how omnipresent it has become in the past, especially thanks to frameworks such as WordPress, and some of the main forum platforms. Based on which website you read, it is currently either in decline or ramping up, but still quite present in the web-dev world. On the TIOBE index itself, it was a winner in 2004 and now it is in 7th place.
It will be easy for you to pick it up if the need arises using your solid grounds from other languages and software architecting skills. Transferable software engineering and architecting skills (think system design, caching, scaling, design patterns) are generally of more value. Once you are in control of harder-to-learn and use languages such as C++ or Java, it will be straightforward for you to implement good practices in PHP where there are fewer default controls in-place other than the human writing the code.
You know PHP very well, should you forget it?
If you already know PHP, don’t disregard that knowledge just because of the general notoriety around it, but instead, try out a few projects and make your own mind about whether you may be able to use it for quick prototyping in this day and age.
At the end of the day, currently, every web host on the planet supports PHP out-of-the-box, so you could quickly host an app made in this language anywhere, almost for free (my favorite web host is DreamHost for ease of use and pricing).
Having been interviewed and having interviewed others, I would say knowing PHP won’t be to your detriment, far from it, but not knowing what’s wrong and what’s right about it when comparing it with other languages and a good understanding of why you are using certain features in specific ways, would show up as red flags. As long as you have a solid grasp of what, how, and why you are using what you’re using then there’s no reason not to make the most of it.
Should you be hiring PHP developers?
This article talks about why PHP is good for startups for example.
Don’t discriminate against or towards PHP developers. And don’t hire someone who claims they know it without having a way to verify the quality of that knowledge and their software development practices.
You should be looking for good team working skills, a passion for technology, algorithmic thinking, and familiarity with why some languages are fit for some purposes more than others in this case. Everything else can be learned on the job quite easily given your interviewee is willing to go the extra mile for stable, testable, readable, and elegant code.
Just as there’s no tool to rule them all, neither does PHP tick all the boxes, however, it’s far from having all of them left blank.
If you already know it, revamp your knowledge, as its performance and features have improved lately quite a lot, and see if it fits anywhere in your career. If you don’t know it then research a few other languages that may benefit your career more in the long term.
Keep in mind there are huge companies that do use primarily PHP (shopping platforms, Wordpress-based sites, Facebook, etc) and that with PHP as your main skill you would be far from out of a job, but it is up to you whether it is the job you want.