Image Credits: Ben Griffiths, Unsplash
It is said that there is no bad language if it allows you to program the necessary patterns to develop most of the existing solutions. While this is true, PHP, despite its improvements over the years, has failed to provide greater efficiency, performance, and native API implementations than most other scripting (and non-scripting) languages.
Let's compare it in its context, with the most used scripting languages today:
TOP Scripting Languages comparison:
Javascript implements asynchrony by default and is based on events, which gives it greater power in managing simultaneous requests, while its JIT (just in time compiler) is notably better than PHP's (later included, in PHP 8) and offers higher speed. On the other hand, in JS you usually need fewer lines of code (therefore easier to maintain) as a general rule.
Also if you need it, you can have static typing with TypeScript (non-existent option -for now- in PHP for example) plus the community, number of libraries, integrations, SDKs etc is much higher.
Python can compile to pyc, which is a semi-compiled and therefore its execution in large computational loads is better than PHP and JavaScript. That is one of the reasons for it to be the TOP in terms of ML (Machine Learning).
PHP outperforms Ruby in resource efficiency now as it has been for a long time.
Some background on PHP: The initial OOP implementation in PHP happened in PHP 3.x and it wasn't until PHP 5 that the implementation was comparable to other languages (again, it was late) and the same thing is happening to it with the inclusion of functional tools whose usefulness has come to the fore in recent years.
In fact it doesn't even implement lambdas yet. It should be mentioned here that Ruby does implement Lambdas (just as JavaScript and Python do).
Something of noteworthy mention is that JavaScript, Python and Ruby are cross-platform languages. You can code from a webservice to an automated irrigation system on a Raspberry Pi, through an application for Smart TVs and even a satellite if necessary with them.
In PHP there was an attempt to create desktop apps with it long time ago, it failed due to lack of efficiency. In the end it would start an apache and run the code there if I'm not wrong, can't even remember the name of it, neither I know if there have been subsequent attempts.
Please note that any language can be a cross-platform language if a platform-specific interpreter is released.
In the case of Javascript, there are even specific frameworks:
- Electron for desktop applications
- React Native, ionic and cordova for smartphone Apps (iOS and Android)
- Node JS or Deno as JavaScript execution environments for servers or hardware
- Browsers themselves (Google Chrome, Firefox, Opera, Edge...) are a runtime that will interpret the client part on websites with Javascript, in which you can use React, Angular, Vue, Svelte...
- Three JS for video games
- etc.
Therefore, in the TOP scripting languages, the pole would look like this:
1- JavaScript (due to its extension, use and general advantages).
2- Python (If we talk about ML, it would be in Top 1).
3- Ruby
4- PHP (if it had Lambdas and covered other deficiencies, it would be in position 3 over Ruby).
For all these reasons, PHP has been relegated mostly to the maintenance and development of plugins or modules for CMS (wordpress, prestashop, etc. which covers the ~50% of the public web currently) and less and less to build microservices or create webApps, because despite being possible, it is not the best option by far.
Is it worth to learn?
If you are planning to learn PHP the question would be "Which target do you pursue?"
If you are going to base your business in CMS plugins/themes then yes, PHP is your language.
If you are going to code Web Apps, the smartest thing to do would be to learn JavaScript and use frameworks such as Next JS, which implements Node JS and React and offers a comprehensive solution to create self-containing APPs, monoliths, etc. if you wish, and taking advantage of the knowledge of this framework, whenever you need to scale it to services or microservices, it's as simple as taking the /api/ directory to another instance, making a few adjustments and running it on top of a simple Node.
If you are planning to do ML, then better pick Python and if you also want to code any website or web app, you can pick Django as python framework to build websites.
Conclusion
To simplify, we can say that PHP is not dead because there are nearly more than 50% of the websites that use PHP (mostly CMS) as their back-end language. But the majority of new projects are using other technologies like Node JS due to numerous of reasons which make it more efficient than PHP.