DEV Community

Cover image for PHP. is it so bad? 2022 check and comparison with other languages
JoelBonetR πŸ₯‡
JoelBonetR πŸ₯‡

Posted on • Edited on

PHP. is it so bad? 2022 check and comparison with other languages

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.

Top comments (10)

Collapse
 
lexiebkm profile image
Alexander B.K.

"React Native and Flutter for smartphone Apps (iOS and Android)"
From what I know, Flutter uses Dart as the programming language. Even before I read about Flutter, I was interested in learning Dart, because it's OOP general purpose language.
But then I didn't find wide acceptance for Dart, although from what I read in its doc, it can be used for web back-end too.
I am interested in Flutter, but still hold on because of Dart. I think, why did Google not use Go instead of Dart ?
That's why, I think I should better learn Java because I think I will be able to shoot 3 birds with one stone : developing desktop non-web, web back-end and Android apps.
For hybrid mobile dev, currently I am still learning React Native. When my learning Java is sufficient, I hope someday I can write native component written in Java which can be imported in React Native (RN) like mentioned in the RN doc.

As for PHP, I still have to use it with Laravel for web back-end. There are still quite a lot of jobs requiring PHP and Laravel.
However, I think I need to be a "Jack of all trades, Master of a few", so I have planned to learn others like Go, Node.js, and probably Rust too. Also, relearn C++ in the correct way.
C# ?... hmm I don't know, the learning curve is steep, because it means I need to learn .Net/Asp.net (.Net Core) too.

Collapse
 
joelbonetr profile image
JoelBonetR πŸ₯‡ • Edited

My bad! πŸ˜… ionic was the word instead flutter, let me fix the post, thanks for pointing it out, much appreciated!

The rest of the comment is more like a question and if you ask me I may need more details like how many experience do you have, previous studies and what are you coding now (platform, target...)?

As a generic response:

Learning thousand languages won't make you expert on a single one.

If you want to target web -mostly- while being able to deliver something for smartphone world (or even desktop) you can go ahead with different languages:

  • JavaScript (as covered in this post) also lets you provide PWAs that can be delivered "as is", or you can also publish your PWA inside Google Play Store and lastly you can, optionally wrap it inside a web view to deliver an iOS app or simply use react-native, ionic, cordova or whatever other FW exists for that.
  • You can go through other paths like C#, see Multi-Platform App UI.
  • Java is a different world. As this guy states in this SO question "There are advantages to knowing Java in 2022, but cross-platform mobile development isn't one of them." (Moreover Kotlin is the official language for Android Apps 😁).
  • C++ is probably more powerful overall but also harder to develop with and maintain, narrower market share and adds some burden to the development process. Moreover you need to pay for some frameworks license such QT
  • Lastly, Dart is a client-oriented language which I suspect is the reason for them using it in Flutter instead Go (server-oriented language).

TL;RD: If your target is multiplatform then Javascript and/or C# are the best options IMO.

Collapse
 
lexiebkm profile image
Alexander B.K.

My background is on desktop non-web, beginning with FoxPro for DOS :):) , which ran both in stand-alone PC and in LAN-Novell Netware. I then switched to VB6, SQL Server, Crystal Reports for developing desktop apps for about 12 years :) , VB.net for only about 1 year. During those years, I actually began to find interest in Java and C#, but couldn't make it into reality.
Knowing that desktop non-web started to become "dead" (like some people said), I turned to web dev using PHP, Laravel for back-end, with HTML, CSS, Javascript and React for the front-end. I only have experience in web dev for about 2 years, being a lone developer, handling a project called Performance Management System which mainly dealt with the so called Key Performance Indicator (KPI), usually used for measuring performance of employees in a medium-large corporation.
Seeing that there are quite a lot of jobs that require Node.js, I began to learn it, although couldn't learn intensively, because I still need to explore PHP and Laravel more, for the same reasons : market demands.
From what I read, Java and C# are still in demands too. But, between these two, my priority is Java. Maybe I will get started with C# someday, depending on my motivation, mood and time.

Knowing that Qt was not free, I have tried GTK for building a small GUI in C++ and found it interesting, but didn't continue because there were other things to do.

Thread Thread
 
joelbonetr profile image
JoelBonetR πŸ₯‡

If you have experience on desktop, also in VB and also some in .net framework... why don't you jump directly to C# .net?
The environment will be the same than using vb.net, the language itself is quite similar to Java and the use-cases for using it are many.
i.e.
.Net features web development as well as Multi-platform so you don't even change the framework if your scope changes, just use some package or another depending on the use case.
Also you can develop video-games targeting desktop, android and/or iOS using C# in Unity.

With your background and your will to learn something to code for any target it will be THE CHOICE πŸ˜‚

Thread Thread
 
lexiebkm profile image
Alexander B.K.

It's between Java or C#. Actually I want both. I know that C# is quite similar to Java, but deep in my heart, like I said, I want to finish my learning in Java first, up to the level I consider sufficient. After that, I will probably get started with C#.
Several years ago, I knew C# and .Net were not free; hence my motivation decreased. But when I knew there was .Net Core, I began to find my motivation again. Still, Java has been always on my mind since 2006, had actually read its official tutorial (text based) offline, but never wrote an actual app. So, I feel it's time to resume my learning that I suspended very long time ago and begin to write an actual app.
Recently, every time I read C# doc, my mind was on Java too. :):)
Therefore, I have to give my priority on Java first; next time when the right time comes, I will spend my time for a journey with C#.
However, it's still possible that I will change my mind later, or at least trying to learn both in different days/hours.

Thread Thread
 
joelbonetr profile image
JoelBonetR πŸ₯‡

If it's so clear then go directly to Java 😁

You know, instead of procrastinating or jumping to a different thing, start with a blank Java file in your favourite IDE and start typing

public static void main(String[] args)
Enter fullscreen mode Exit fullscreen mode

and begin adding more lines. It can be a calculator that works through the terminal and it will be good. The most important thing for you is to finish something that's little and then checking for bigger (or just different) things.

Also share your learning on Java, I want to read your steps with it! 😁

Thread Thread
 
lexiebkm profile image
Alexander B.K.

I am accustomed to getting the fundamental concepts first, like classes, objects, packages, annotations, interfaces, inheritance. I am currently on interface, specifically on default methods. I usually try the code samples given in the official textual tutorial, modify in some parts to try my own idea, using only Javac compiler (although already installed NetBeans and Eclipse).
But I need to be patient this time; so my plan is : after I "finish" with generics, I will visit Spring Boot to resume my learning on it for developing back-end (REST API) for my React app. Actually I want to proceed to J2EE, but it will take longer time. The use of annotations in Spring for declaring a controller class as well as for mapping HTTP verbs to the corresponding class methods look beautiful to me.
I find the use of decorators in Angular framework for similar purpose looks beautiful too; no wonder Nest.js (a Node.js framework) is heavily inspired by Angular on its architecture.

Thread Thread
 
joelbonetr profile image
JoelBonetR πŸ₯‡

That's nice. I get boring if I only get theory beforehand, I need to put myself hands on and increase my knowledge through this do -> read -> do cycle πŸ˜‚

Collapse
 
rvandervelde profile image
Remco van der Velde

Php with a decent framework like laravel/symphony will do the job nicely

Collapse
 
joelbonetr profile image
JoelBonetR πŸ₯‡

Didn't say the oposite, just that it's is not the best option.