loading...

Three reasons I like PHP more than Modern Javascript

twitter logo ・1 min read

I use PHP for backend and ES6 code (usually with React) for front-end.

Here's why I like PHP more than Javascript

  1. PHP has most of its features in-built. That's pretty much compared to Javascript. And, no bunch of import statements. Autoloading is absolutely cool.
  2. I don't have to install 100MB+ files to start a new project. Just creating a folder and running it via a browser.
  3. Async in Javascript is quite good, but not always. Sometimes, I end up with many nested callbacks.

One thing I like about Javascript (ES6) is that it's concise. No unnecessary stuff.

Ex: Defining a publish non-static function
JS

class X {
    getMeta() {

    }
}

PHP

<?php
class X {
   public function getMeta() {

   }
}

True, visibility in PHP is fine. But, why function? getMeta with () cannot be a property. 🤔

These are just my thoughts. What are yours?

twitter logo DISCUSS (11)
markdown guide
 

I agree that PHP is still powerful and great for back-end development, but I don't think PHP is more feature-rich than JavaScript.
Second, you don't have to install a 100 MB of dependencies for a simple project you can only have your simple JavaScript files. The dependencies of JavaScript are heavy sometimes that's correct, but PHP dependencies can be heavy too. So literally, PHP is no better than JavaScript in terms of a simple project.
Well, for the third thing you've mentioned, it is absolutely right. Although it is possible to use async and await, you'll need the callbacks again somewhere since it's JavaScript's nature.

 
 

I'm just glad for this post :) I'm Java developer originally and when I need sometimes lightweight for web, I use PHP or Python. I use JavaScript on client-side, of course, but on serverside - nooooo. I had projects in Node.Js and they left feeling of language which is quite clumsy in bringing together all new features, inconsistent and illogical sometimes (with all those [] + {} vs {} + [] jokes) - and really weird when dealing with callbacks and promises.

I don't doubt it is quite possible to write almost anything in JS (as it has good engines nowadays), but it is really hard to be happy with it, especially if the project / team is large.

 

The reason I like PHP better is the fact that it runs on the server, which means you have ultimate control over what it sends to the client. JavaScript, however, runs on the client, unless you use Node.js. This means it's subject to how the browser interprets your code and displays something accordingly. I like the ultimate control the server side code gives me.

If you're looking at syntax, I honestly don't have a favorite. They're both different and I appreciate both ES2015 and PHP 7.4 for what they are.

 

In a simplified manner, you wrote your comment as if php has clearly the advantage because it can't run on client. What? :)

 

I mean...yes, essentially! It's a benefit to me personally because I like to control every little aspect of the application environment. With PHP you can, because you control everything on the server. With JavaScript (on the client-side) you're at the mercy of the specific implementations of the browsers and hope they interpret your code exactly as you have intended it to.

I'm not saying one is better than the other because I work with both on a daily basis. But to answer your question, yes, to me it has an advantage that PHP doesn't run on the client-side.

If we're talking about Node.js on the server they're equal, because PHP no longer has the benefit over JavaScript in that scenario.

You're talking about node.js as if it is another language and php just works on thin air. And you compare bananas with carrots.

Let me put it this way. With php you can control only bananas. With javascript you can control both banana and carrots.

I don't think I've explained myself correctly because that's not what I mean. Let me try again.

PHP doesn't run on thin air and I never meant to suggest that it does. It runs on a server than I can configure and I can control exactly which software packages should be installed.

I understand why you think that I'm saying Node.js is completely different from JavaScript. Of course, it's all just JavaScript and it's not different at all. The reason that I mentioned it, is that it's the way to run JavaScript on the server and that's why I'm only comparing Node.js to PHP because they both only run on the server. PHP can't be compared to client-side Javascript. As you said, they're apples and oranges.

JavaScript is much more versatile and you can do a lot more with it than PHP. It's great on the server and also on the client.

PHP is only on the server. I personally like this much better because I can control everything about the server, which means I control everything that's going on. I like the control, but this doesn't mean it's clearly better than JavaScript. Just because I like control doesn't mean I urge others to only use PHP. Use the right tool for the job.

I'm not saying in any way that PHP is better than JavaScript. They're both great, I use them both with great joy. So I completely agree with you that they're not completely comparable and only compare on one aspect, the server.

I was initially only thinking of JavaScript on the client-side, which is why my point of view might have been very confusing. Apologies for this confusion.

These are all my own preferences and I'm not implying that one is better than the other and therefore everyone should pick one over the other.

I hope this explains my point of view a little bit better. Just know that I completely agree with your comment about the banana and the carrots, you're right.

 

The verbosity of the PHP is true. If the language follow the CoffeeScript or Python and remove unnecessary parentheses and braces in a dialect PHP can be better.

 
 
Classic DEV Post from Nov 1 '19

How I Got Hired at DEV (and Every Other Tech Job)

01010011 01110101 01110000 profile image
Seeking success