Why PHP isn't bad
h
Baconman321 (594)

I

know this isn't necessarily a tutorial, but I have heard so many people say PHP is bad. This, of course, is 100% wrong. PHP is amazing, and if you understand what PHP is and what it does, you will probably agree. So, let's begin my rant on how you shouldn't shame PHP, shall we? Also, I compare PHP to Nodejs a few times, and that is because Nodejs is used a lot in backend. I have used it a few times, and I just want to compare it to that to show you guys that PHP is, in fact, good. Most backend developers here use Nodejs also, so that is another reason.

Reason 1: PHP is popular!

According to W3Tech's data, about 78.9% of all websites known to use backend use PHP, whether they use a combination of both, or solely PHP. That's about 8 out of 10 websites you visit using backend! Can't beat that reasoning, right? But, does that mean that PHP is good, or are so many websites outdated? After all, PHP is OLD!!!

I hate how so many people say that PHP is old and therefore not suited. Oh yeah guys, we shouldn't use C++, JavaScript or even Python (yes, python was released in 1991) because they are all old, and therefore, outdated languages.

The next time you consider calling a programming language bad because it's old, consider whether you want to call your favorite programming language bad.

Reason two, it's easy!

Ok, this is relative, but I find PHP quite easy to use. In PHP, you can get a parameter from a query string using the single global variable like so:

$something = $_GET['somethingElse'];

In Nodejs (I did some research since I know very little of Nodejs, you either use a framework (which takes up disk space), or you take a trip down to complexville. Note that this isn't really as complex as it sounds, but definitely more lines of code than PHP. Here's how you would parse a URL:

const querystring = require('querystring');
const url = "http://example.com/index.html?code=string&key=12&id=false";
const qs = "code=string&key=12&id=false";

console.log(querystring.parse(qs));

Technically, this is a custom query string and not the actual url, you would have to get the request object and all. Of course, post requests are stored in the $_POST variable in PHP. What about in Nodejs? Well, that's a whole other story. Now, before you go on saying "well, then that's actually better since it provides more control", let me just say that do you really need that many lines of code for a single GET or POST request? Of course, you can always get the request URI by accessing the $_SERVER["REQUEST_URI"] in PHP. This, I find is much easier than, say Nodejs.

Reason three: It's convenient

PHP is high speed, argue all you want. It uses its own memory, so both workload and loading times are cut. It is also open source, so no need for additional, pesky excess software to get it to work. Another thing, it can be embedded into HTML. Yes, you heard me right. No more setting up a file and having to send your HTML using res.send or another way of sending things to the webpage. PHP can work like so:

<!DOCTYPE html>
<html>
   <head>
   </head>
   <body>
   <?php echo "hello world";?>
   </body>
</html>

Of course, you have to send elements you want to dynamically add using echo, but any static html tags in your website can be put in right then and right there, no need to send it using 100% PHP. It's syntax may look weird compared to other languages, but I still find it comfortable to work with. Plus, the file handling is easy too. Say what you want, but PHP is great to work with.

So, should PHP replace every backend technology, Mr.rageman?

Certainly not!
I am not asking for people to drop all their precious backend languages like Ruby, Go, Nodejs, Flask, and so many others. I am merely asking people to give PHP the respect it deserves. I have heard that PHP can even be used to code drones (I couldn't find much info on that though)! It can be used for anything from backend, to making your own programs. And while there are many different libraries for PHP (yes, it's still popular as much as you may beg to differ), it's also completely functional without them.

So, should I give PHP a try then?

Yes!!! Please, DO GIVE PHP A TRY! It is great to learn, fairly easy, and gives you lots of control. That said, I am not shaming other programming languages in this tutorial, I am merely comparing them to PHP, and showing how PHP offers different perks than them. There are plenty reasons not to use PHP, but I think you guys should really try it; only then will you see how awesome it can be. It may feel old, but old doesn't (and generally shouldn't) mean bad.

We respect our elders, maybe it's time to respect the elder by the name of PHP.

You are viewing a single comment. View All
Baconman321 (594)

@19wintersp I think "security issues" is just something people say without researching. PHP has some vulnerabilities, but there are also methods in place to avoid that. The only "security issues" are the people who forget to put those methods in place to prevent people from hacking their program/site. Nodejs has those built in security methods, which may be more convenient, but as for me I find PHP more low level that way.

And as for syntax, yes it's weird. Still, take python. It's syntax is off the chart in weirdsville. And also, indenting is key for python, so there is no proper file minification because of that. Don't put off a language just because it has weird syntax. Plus, nodejs has security vulnerabilities too, and while it's syntax isn't too bad for me (since I know js), it has weird ways of writing to the webpage/receiving data.
Here, to read more: https://www.getastra.com/blog/php-security/fixing-php-security-issues/