DEV Community

hrishikesh1990
hrishikesh1990

Posted on • Originally published at flexiple.com

PHP vs Javascript - What should you choose?

In this short tutorial, we take a closer look at a controversial topic that is PHP vs JavaScript. We look at their pros and cons and weigh them against each other.

This tutorial is a part of our initiative at Flexiple, to write short curated tutorials around often used or interesting concepts.

Table of Content

PHP vs JavaScript: An Overview

Most blogs under this topic would mention that comparing PHP and JavaScripts are like comparing apples and oranges. However, the rationale supporting this is - PHP is used on the server-side, whereas JavaScript is primarily used on the client-side. Although javascript is largely used on the client-side, the development of NodeJS (A backend framework) has made javascript a full-stack programming language.

Even though this does not level the playing field it does beg the question of whether a developer should choose - JavaScript/ PHP or developer the entire website using Javascript. And this blog is aimed towards answering this question.

JavaScript - Pros and Cons

JavaScript has been around for ages since 1995, this has not only allowed the creators to refine the language but has also helped grow a large community of active users. In turn, resulting in a plethora of well-documented tutorials and troubleshooting methods readily available on the internet.

JavaScript as a language was developed to create dynamic and interactive websites improving the user experience. Catering to the client-side it was built to have minimal server interaction, reducing the load on the server. And because of this high-performance Javascript is often used on one-page websites and streaming platforms. The pros of Javascript don't stop here, the introduction of frameworks such as ReactJS, AngularJS, VueJS, NodeJS, etc has made it an extensible language. And with each framework offering different functionality and performance developers are quick to adopt them.

This leads us to our first con, given its vast usage the learning curve can be quite intimidating, and with each framework offering a different syntax it would require significant dedication and practice to master them. However, the returns on doing so are quite significant and in case you are looking to enter mobile development, javascript is the way forward. Another major con when it comes to using Javascript is security. With the source code easily visible to anyone, it has become a major concern. There are ways for you to enhance security but these methods would require additional effort.

PHP - Pros and Cons

PHP is a general-purpose language that has also been around since 1995. Similar to Javascript, PHP also has a large active community and was built to suit web development. And since PHP has always cantered to backend development it has a rich library and support to more features and much better security than javascript

Areas, where PHP stands out, are its seamless performance with Content Management Systems like Word press, Drupal, etc. This is why PHP is commonly used in blogs, Media, and E-commerce websites. Another pro is its compatibility with serves like SQL, MariaDB, Postgresql, etc. The only con I have faced while using PHP has been its performance - Unlike Javascript, PHP is synchronous and this makes it lose out on speed and performance.

When it comes to the learning curve, PHP is significantly easier. Tasks such as setting up a server are quite simple, and the frameworks as well can be easily learned without many prerequisites.

Closing thoughts - PHP vs JavaScript

If you have reached it this far you must be aware of the pros and cons of each language. And it must be quite evident that choosing between the two would boil to the use-case and the developers' knowledge of the languages. My personal choice would be to chose JavaScript/ PHP while working on complicated websites as this would allow you to get the best of both halves. A few famous websites that utilize this are - Wikipedia, Facebook, Yahoo, etc.

However, if you are competent in Javascript and looking to build a smaller one-page or streaming website - hands down javascript all the way.

Top comments (9)

Collapse
 
careuno profile image
Carlos Merchán

JavaScript

Collapse
 
andreidascalu profile image
Andrei Dascalu
  1. The way you wrote, you focused on client side JS, but if you want to compare from a dev perspective then node is worth mentioning.
  2. Php server setup may be easy (at least for a dev environment) but it's there. The vast majority of platforms don't need any setup to spin up an api.
  3. Php may not be asynchronous out of the box, but there are extensions that fix that. Let's not forget that technically dB support also comes from extensions, though stuff like mysql is enabled by default. You have swoole that provides actual concurrency (not just async) and roadrunner that provides a high performance multithreading environment.
Collapse
 
adam_cyclones profile image
Adam Crockett 🌀 • Edited

JavaScript is primarily used on the client-side

This was true when I started 10 years ago, it's absolutely not the case now

Collapse
 
hrishikesh1990 profile image
hrishikesh1990

Completely agree with you. I didn't mention that in the following line. :)

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Graciously received feedback, I like that 😃

Collapse
 
huhu08 profile image
huhu08

PHP

Collapse
 
gmarokov profile image
Georgi Marokov

Definitely go away from PHP. Its syntax will confuse you and make it hard to adopt another languages. Its also super anoying. You can do it much better with JS for example or some OOP language like Java/C#. I wrote PHP for years, not saying this because of hatred.

Collapse
 
peter279k profile image
peter279k

I use both of them.

Collapse
 
xem0n profile image
Xem0n

great article, however nodejs isn't a framework, but a runtime environment