Software Development
Sebastian Luczak
Sebastian Luczak
PHP Unit Leader
2022-06-28

Two Reasons You Should Not Use PHP

As a PHP developer I still remember the days of PHP4, the first (optional!) GC implementation in PHP5, and I lived through the _hype_ of the advent of PHP7 and its ramifications.

​Over the years many people have asked me why I bother programming in PHP, and for many years I've heard like a mantra two recurring arguments why I should stop and start writing commercial software in languages like Java or C#. ​ Today I'm going to quote those arguments and try to change your attitude towards PHP at least a little bit. Yes, the title of this article is an absurd clickbait.

image

#1 PHP is dying

PHP is dying year after year. The once most popular web language is now losing popularity month by month, mostly to JavaScript.

​ When you look through the numbers, the truth is sobering! Over the past year, PHP lost a staggering 1.6% of its share as the backend language of the Web.

​ If PHP continues this downward trend, in 18 years PHP will drop below 50% of the backend Web technology!

Historical trends in the usage statistics of server-side programming languages for websites

​ But okay, jokes aside - although the numbers are real as reported by W3CTechs.

The first mention that PHP is dying can be found on the web since 2013. Back then Software Gunslinger published an article (which by the way I highly recommend!) saying that PHP will die because it doesn't support long-lived processes and because it lacks asynchronicity.

​ And that's a fact, PHP was not made for that!

if all you have is a hammer, everything looks like a nail

​ But back to the numbers - let's take a look at last year's data on PHP versions used in Packagist packages. The latest data is available at the source site packagist.org

Package installations by PHP minor version graph

​ Is this the adoption curve for new versions of a dying programming language?

​ If that's not enough, let's check our "PHP death rate" against other languages. ​

The data for the analysis is taken from ​GitHut 2.0, which generates a chart of the number of git push per language to the Github since 2012, according to the scheme - "The language percentage distribution in the line chart shows the top 10 (or manually selected) languages since 2012/Q2".

programming language precentage distribution graph

​ As you can see PHP as well as other popular languages such as Ruby, C/C++, Python have experienced a significant drop in popularity on Github in recent years, however there is an upward trend and we expect them to return to high positions after a longer sideways period. (this is not investment advice)

​ The initial hype for the Javascript language can be seen in the same chart. I will already leave the conclusions and its analysis to you, dear reader.

image

​ But then again - a dying language shouldn't tend to increase the number of job offers for programmers, right? ​

image

​ As of the moment of writing this article, I can choose from 171 job offers on one of the leading job portals in Poland, of which as many as 50 are for juniors. PHP is dying, right? ​

PHP meme - php is dying

​And speaking of money... did you know that PHP and its source code has been maintained since November 2021 by the independent Open Source community ​The PHP Foundation which pays substantial money to OpenSource developers for contributions to php-src?

​Unlike other languages and frameworks, which are often owned by large companies, the core development team is paid directly from the foundation's account which is run by contributions from private companies such as JetBrains and Symfony Corp but also by ​small contributions from individual developers.

Open Source in all its glory!

#2 PHP is dreadful

Yes, this argument always comes from the mouths of developers who have become familiar with strongly typed, comparable languages. ​ Looking at the graph of data collected during the ​StackOverflow survey of 2021, you can see that as many as 10,834 respondents representing nearly 60% of the total found PHP to be "dreadful".

image ​ As an old-school PHP programmer, I understand why this is so. I am immediately reminded of a classic example of memory problems in PHP: ​

<?php
 
class FOO {
  public $f;
}
 
class BAR {
  public $f;
}
 
while(1) {
  $a = new FOO();
  $b = new BAR();
  $a->f = $b;
  $b->f = $a;
  print "Memory usage: " . number_format(memory_get_usage(true)) . " bytes\n";
  unset($a);
  unset($b);
}

​ For the uninitiated - yes, the above code causes a memory error. And there's more. ​ From the idiotic naming of methods and the complete lack of logic in the order of their parameters (yes, we all love str_ and array_) to PHP's most famous bug T_PAAMAYIM_NEKUDOTAYIM - PHP is full of quirks and vices of old versions. ​ This does not mean that what we heard about PHP a few years ago is still true. The language has undergone a huge metamorphosis and today I'm happy to look at my object definitions: ​

readonly class NotificationEvent
{
    public function __construct(
        public string $context, 
        public User $user,
        public string $body,
        public DateTime $issuedAt,
    ) {}
}

​ What's more, the PHP ecosystem has grown tremendously, and we now have incredible opportunities to create good, highly typed, and well-tested code. ​ We can use Symfonyto develop DDD applications without any major problems, and we can work around the problem of PHP's synchronicity by using Message Bus.

And while I myself don't think PHP is suitable for creating long-lived backend processes and has huge performance issues when it comes to state synchronization, I've also ​created a PHP console game using Symfony + Docker with my own hands as an example that PHP can still have unconventional uses.

​ Another advantage of PHP is its low barrier of entry for new developers. ​ Documentations of two popular frameworks Symfony and ​Laravel and PHP documentation itself are enough to enter the backend world with their help. A world that is not perfect in PHP but allows for a lot. Using additional libraries such as Laravel Nova we are able to create almost any component of our system with just two commands.

Afterglow

​ Is PHP dying?

No, but it has an image problem and needs a lot of work to improve it. We, the programmers, have to do this work by teaching the new generation and passing on best practices in the form of articles, libraries, and tips.

As a language that has been on the market for twenty years, which has already survived more than one hype (remember Objective-C?) I think it will cope and find its niche. ​ And who knows, maybe my predictions will turn out to be correct and PHP 10.x will boom again in two years?

PHP development free consulting

Read more:

5 Mistakes You Should Avoid While Maintaining a Project in PHP

PHP Development. Symfony Console Component - Tips & Tricks

Why do we need Symfony Polyfill (... and why we shouldn't)