9 Reasons to Use PhP In 2022.

9 Reasons to Use PhP In 2022.

Table of contents

No heading

No headings in the article.

why php.png Introduction

PHP - Many love to hate it, and yet many, many more use it. Open any Reddit thread or any popular Twitter post and they’ll have the 3 words. And you won't miss someone bashing on it.

In this article, I am going to ignore all that and convince you why you should pick PHP for your next project in 2022, and beyond. Let's go.

Nowadays, It's much more than just a web server scripting language, It probably still is the best for this. And on top of that, You can build Api’s, background processes, and CLI applications

Before we continue, let's first understand why people make fun of it.

Why The Hate?

Most developers love to make fun of the language, here are some of the top reasons why.

1. Misguided Perception

It's true to say that most people who hate PHP do so based on what their developer friends say and the first google search. But that’s not it. People follow celebrities, trends, and what is perceived as cool, for a few years back during the days of PHP 3. The language grew so big, as it’s still the most popular language, lots of developers come in and the language isn’t a fit for all of them.

This group of rogue devs gets frustrated and when they see a new shiny language they start to fantasize how amazing their life would be if they were coding in it other than being stuck with maintaining this legacy app.

Look at javascript, People hated it. Many of them but when its perception changes. Mainly because of NodeJs and that made way for es6, es2016, and just the explosion of frontend frameworks like react, angular, and many more after that. Just because of how its perception changed, not the language.

2. Dark Past

PHP has come a long way since 1994. It was originally intended to be a templating engine on top of C lang, Just like Twig, blade, or jinja for python forks or ejs in nodeJs world. But who are the users?

Developers found it so easy to use and wanted to do everything in it. With the lack of a proper design, features just got slapped into the language without a proper design. This made the language grow far beyond the maintainer’s dream. The creator has openly admitted he hates programming. But this brought so many things to PHP.

Libapache extension allowed apache web servers to execute PHP scripts, something never before.

user apache.png

ext-MySQL, now deprecated, made it simple to create dynamic web pages back when static was the norm

With the pressure from users for the language to do more, and lack of a proper vision of the future, it brought about lots of inconsistencies, unpredictability, and a few gotchas here and there.

Hat’s off to Rasmus Lerdorf and the early development team for their contribution towards PHP, for as if not for them, We couldn't be here today. They say it's the need that brings about innovation, and not the other way around. PHP stands true to this testament

3. The syntax

Php has a few issues with the syntax, mostly just naming inconsistency, to be honest, still bothers me, but the haters just have this OCD which is hard to look past. Here are a few built-in function examples:

a) nl2br() - it has a number, but other built-in functions don’t .

b) Underscores vs no under score e.g fopen(), str_replace(), strtolower(), str_shuffle(), this is the case for many more functions

c) Unnecessary functions - for case sensitive string functions vs case insensitive e.g str_replace() vs str_ireplace(). We have strtolower() already, why add another?

I could go on, but those are just a few examples of issues with syntax, there's more to do with parameter ordering but I will stop here.

4. Legacy Applications

We developers really hate legacy. PHP being the most popular used programming in production, Most developers have just been swept into it because of circumstances and are now stuck maintaining it. Those who moved on to other fields are stuck thinking PHP is still in the days of PHP 3.

5. Lack of Libraries

Well, PHP in essence doesn't suffer from a lack of libraries to do most things, especially when it comes to web development. It works hand-in-hand with javascript and most things that it can’t do, Js can. But if you want to work with modern libraries like in machine learning and AI, you will be stuck with doing FFI calls as most of these libraries aren’t natively written in PHP.

So, Why Turn To PHP?

why turn to php.jpg Now that we’ve looked at why people love to make fun of PHP, I am going to give you factual reasons why PHP is the best choice for your next project. Okay, I won't bother you with how it's used by 80% of all websites including Wikipedia, Facebook, and Slack. Just some hard-core technical facts on why developers still choose it, even if they are ashamed to speak of it publicly.

1. PHP is fast

You heard that right, PHP compared to other interpreted languages like Ruby or Python, this is largely due to its architecture, and by that I mean it has close ties to C language. Also, the PHP core team did a lot of work when shipping PHP 7 by rewriting the underlying code to improve performance and they achieved it. This release alone more than doubled performance compared to previous versions.

2. Fast Development Cycle

So you have a website built with HTML and CSS, it's perfect – right, but you want to add a bit of dynamic content here and there, simply rename your .html files to .php, then add php magic tags, Voilà, It works.

fast dev.png

Since PHP just rendered every HTML code by default, renaming .html to .php works without changing anything,

When you rename, it brings this whole new power of executing code on the server. From here you can

  • Access the database, Mysql, Postgres e.t.c

  • Schedule background tasks

  • Call external API’s

Not just that. Since PHP is an interpreted language, you can quickly edit files, save them and reload the page and instantaneously see the result without any compilation, watching files, or restarting the server. This alone makes it so lucrative compared to other compiled languages.

Did I mention that it's cross-platform?

3. It’s Everywhere

Say you want to build a blog, I bet your number one choice is WordPress unless you’re that developer who doesn’t like building on what’s already existing. You could pick your favorite framework, e.g laravel, Django, or express, and start building a site just to allow you or your customer to show a landing page, what they do, and dynamic content here and there.

Would you rather start from scratch, or pick a nice WordPress theme(what the heck you can even build your own) deploy a site, and be up and running in a few days or spend weeks iterating on Figma files, then move to HTML and CSS? Businesses appreciate quick turnaround time, pick a tool that will help you achieve that, and WordPress is the best for this scenario.

As WordPress is built with PHP you can even build your own WordPress themes , sell them and start earning with your basic knowledge of web design. Php makes it easy for you to transition to the backend and full-stack development.

4. Rich Libraries

Ever had a composer? It's a PHP package manager, same as npm in nodeJs land and ruby's bundler.

Via packagist repository, PHP offers hundreds of thousands of libraries that you can easily pull in with composer, and immediately start using it. It's also more than just a package manager, it autoloads your files and sets config for scripts run via composer.

5. The Community

This is a huge one, PHP has a huge community of developers, building tools, frameworks, libraries, and guides to help any new developer. Post any question on StackOverflow and you will have answers on it.

On Frameworks, Php shines. It boasts the most popular backend framework Laravel. In itself, it has a huge ecosystem built around it. Like laravel forge for server management, laravel vapor for serverless, jetstream for scaffolding among others.

Other popular frameworks include Symfony, Zend, SlimPhp, Yii, e.t.c. Frameworks make up a huge chunk of new job opportunities as they make it easier for new developers to jump into a team and get up and running quickly and become productive.

PHP frameworks are well designed, intuitive, and hide away the dark past of PHP, Look at this code excerpt from laravel

php community.png

In just a few lines, we’ve received the user id. Queried the DB and displayed it. No extra fuss. Beautiful!

And when do you want to validate input?

php input.png

See, SQL queries, no if statements. No extra checks for doing basic CRUD stuff, no boilerplate. That’s how beautiful your code is with PHP.

6. The Flexibility

Out of the box, PHP offers so much flexibility to developers. And I am not just talking about how you can embed HTML to php scripts, There's much more, you can run multiple versions of Php but you already knew that. It's not a strictly typed language like Java but it's more like js or py.

But I would say the most important one of all is its Reflection API . you might think you’re not using it daily but if you're using a framework and wondering how a route receives its arguments in any random order, that’s DI. reflection API gives framework and library developers the ability to introspect, initialize classes and pass in arguments to methods.

Dependency injection on its own requires its topic, but for the years I have been a developer, so far I haven’t found a language that does DI and auto wiring the way PHP does.

7. It's less expensive

This is the most underestimated consideration out there. Outside of the realm of fortune 500 companies, there are small businesses. This is equally as important to any backbone of an economy as the bigger ones and is most likely where most will be employed or looking for business partnerships.

Businesses value cost savings, assuming you're delivering software that meets their business needs and can evolve as the business grows, Php is the answer for this, most shared servers are offered with PHP by various hosting companies, and when the time will come to scale, Php will just as well as java or any enterprise language you might think of.

8. It's easy to deploy

Just put your php files in apache’s root folder, install libapache and you’re good to go. Too easy? Yes, it's that simple. But if you’re looking for something more sophisticated, PHP also offers php-fpm which you can pair with applications like Nginx to execute your php applications

9. The promise of the future

In as much as I don’t want you to get into php just for the promises alone, I wanted to point out to you what’s going on in the PHP development community lately, At the time of writing this, I can confidently say that PHP has been in a very active development cycle since the release of php 7.0 back in 2015, which shocked the IT community with the performance improvement which more than doubled, right now. We’re in PHP 8.1. PHP 8 on its own brought in a whole lot of features and improvements that make the language better and more performant.

With this continued trend, PHP is destined to improve and grow over time. The development team is also steadily fixing the design issues that the language has had since the early days but most will stick around for long. If you are the kind of person that will bang your keyboard over why function X has an underscore and function Y doesn't, the php isn’t the way to go.

To sum it up

PHP, like any language, is just as powerful and might be the right tool for your next web development project or an API that you’re building. As much as we love following trends and jumping to the next cool language, Remember to use the right tool for the job and that could be PHP for you.

Nixon Kosgei