PHP 8.2: ¿Qué hay de nuevo?
La nueva versión de PHP está a la vuelta de la esquina. ¿Cuáles son las nuevas implementaciones que debe conocer? Consulte este artículo para saberlo.
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.
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!
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
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”.
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.
But then again – a dying language shouldn’t tend to increase the number of job offers for programmers, right?
As of the moment of writing this article, I can choose from 171 job offers on one of the leading job portals in Polonia, of which as many as 50 are for juniors. PHP is dying, right?
And speaking of money… did you know that PHP and its source código 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 equipo 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!
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”.
As an old-school Programador PHP, 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)) . " bytesn";
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_
y 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 Symfony to 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 y 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.
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 mercado 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?