News: 1606410011

  ARM Give a man a fire and he's warm for a day, but set fire to him and he's warm for the rest of his life (Terry Pratchett, Jingo)

Marmite of scripting languages PHP emits version 8.0, complete with named arguments and other goodies

(2020/11/26)


Version 8.0 of the PHP scripting language is scheduled for release on 26 November, which coincides with the US Thanksgiving holiday.

PHP [1]turned 25 earlier this year and its latest iteration brings a variety of improvements to those who enjoy the language, which certainly isn't everyone.

Type "is PHP" into Google Search box, in Incognito mode, and the first two auto-complete suggestions you'll see are "is PHP still used" and "is PHP dead."

It is and it isn't: PHP still ranks as the eighth most popular language in the [2]Tiobe index , just below JavaScript. Nonetheless, PHP has something of a mixed reputation among developers.

Developer survey: C# losing ground to JavaScript, PHP and Java for cloud apps, still big in gaming [3]READ MORE

"Despite still being one of the most used languages to build web applications, over the years PHP has managed to get itself a reputation of messy codebases, inexperienced developers, insecure code, an inconsistent core library, and whatnot," wrote Brent Roose, a PHP programmer with Belgian company Spatie, in a [4]blog post at the start of the year.

Roose went on to argue that developers can write clean, fast, maintainable, reliable applications in PHP. As with other languages, ill-behaving code is often more a reflection of developer experience than language deficiencies.

In an interview with The Register , Mark Story, a principal developer at application monitoring biz Sentry and maintainer of CakePHP, acknowledged that PHP has some historical baggage.

"I would agree that PHP has a very mixed reception when you bring it up," he said. "And I think a lot of that has to do with how historically PHP has been used. Some of the very large PHP projects have not always had the best coding practices and then those projects have been kind of trapped in a stage where they can't really work their way out of that problem, because they have a huge community and a huge amount of inertia behind the existing code base. Replacing it is just really, really challenging."

Story added that he believes PHP has developed a bad reputation because, being easy to learn, it gets picked up by a lot of novice developers early in their careers. "So you get people who maybe don't have formal training or maybe don't know all the best practices and then they fall into the pit of success where PHP just does what they need to do," he said.

[5]

Click to enlarge

The thing about PHP is there's a lot of it – in websites where the server-side programming environment is known, [6]79 per cent of them use PHP. WordPress is written in PHP. And for what it's worth, Facebook was originally written in PHP, though the ad biz has since shifted to a dialect called Hack, in addition to other languages.

Among the noteworthy [7]features in PHP 8.0 , Story pointed to improvements in the type system, like the addition of [8]union types , which allow variables to be declared to hold data of more than one type. For example, a variable could be declared to hold either floating point or integer data.

"Another big one is [9]named arguments , which is a feature that's been basically stolen from Python," said Story. "One of the key things that people love about Python is being able to use named parameters and not have to worry about the position of the parameters as much and not have to wrap them in another structure like an array."

Story said while PHP makes sense for web servers and command line tools, it isn't great for other uses. And he doesn't expect the 8.0 update to change that.

"I think it doesn't open up any new opportunities for PHP," he said. "What I think it does is just improve the quality of life inside of PHP. Another interesting thing that could be beneficial in the future is the just-in-time compiler, the JIT compiler. It won't be super useful in most web stacks right now just because the code doesn't get hot enough for the JIT compiler to kick in. But it's promising. It's the start of something that could be really powerful in the future."

Those planning to upgrade to PHP 8.0 should test their applications before making the jump, said Story, who suggested waiting a few weeks or months until the library ecosystem and all the dependencies get updated. ®

Get our [10]Tech Resources



[1] https://www.jetbrains.com/lp/php-25/

[2] https://www.tiobe.com/tiobe-index/

[3] https://www.theregister.com/2020/10/21/developer_survey_c_losing_ground/

[4] https://stitcher.io/blog/php-in-2020

[5] https://regmedia.co.uk/2020/11/20/php_image.jpg

[6] https://w3techs.com/technologies/details/pl-php

[7] https://github.com/php/php-src/blob/php-8.0.0RC4/UPGRADING

[8] https://wiki.php.net/rfc/union_types_v2

[9] https://wiki.php.net/rfc/named_params

[10] https://whitepapers.theregister.com/

You know the script

Anonymous Coward

(pardon the pun)

Angry comment shitfest coming in 3, 2, 1…

Google

Anonymous Coward

> Type "is PHP" into Google Search box, in Incognito mode, and the first two auto-complete suggestions you'll see are "is PHP still used" and "is PHP dead."

To be fair, Google results for some reason seem to be biased towards constant negativity, no matter what your search term is (permanent private browsing here).

Entanglement

Anonymous Coward

"Some of the very large PHP projects have not always had the best coding practices and then those projects have been kind of trapped in a stage where they can't really work their way out of that problem, because they have a huge community and a huge amount of inertia behind the existing code base."

Gosh, whatever popular blogging platform for pressing words onto the screen could you possibly be referring to...?

then they fall into the pit of success

Dave559

Hehe, "pit of success", that's a great phrase. I must remember to find excuses to use that…

Anonymous Coward

> Story added that he believes PHP has developed a bad reputation because, being easy to learn, it gets picked up by a lot of novice developers early in their careers. "So you get people who maybe don't have formal training or maybe don't know all the best practices and then they fall into the pit of success where PHP just does what they need to do," he said.

To be fair, the same could be said of many a language, including for instance Python which I'm not a big fan of, but it doesn't have the same reputation. One thing that did set PHP apart back in the day, though, is that it wasn't originally "designed" as such. It was more of a quick hack by a guy to make his life easier when writing CGI scripts, so there were some pretty big holes in the early implementations that were trivial to exploit (like much CGI at the time). I guess we were all still in the age of innocence back then.

It did me great service in the first decade of this century, but around 2012, when time came to set out the requirements for a new project, I just couldn't see myself inflicting PHP upon the team and I. My feeling was that it had become rather unwieldy. Not claiming to be right, just sharing why I moved away from it. Your experience may be different and if you're happy with it, so much the better.

Ian 55

It's also appallingly inconsistent about what a library function that does something is named.

And it's from the people who thought testing if an integer variable is bigger than maxint was a good idea in a test with security implications.

Dave559

"It did me great service in the first decade of this century, but around 2012, when time came to set out the requirements for a new project, I just couldn't see myself inflicting PHP upon the team and I."

Just out of curiosity, what language did you choose instead?

werdsmith

I expect there is work for code maintenance for PHP, but I assumed nobody in 2021 is going to start a new project with it. I recently found a number of books about it in my garage. They have gone for recycling,

theOtherJT

Depends what you're trying to do I suppose. I'd still rather write PHP than python if I'm doing webapp type things, but I'm sure everyone has their go-to language for a certain task.

Thought About IT

I found the Laravel framework good for recoding my web site in PHP.

tin 2

PHP... misconfigure your webserver (or have it misconfigured for you) and there's your undercrackers on display in public. That's probably a massive oversimplification but is the reason I stayed away.

?

DJV

If the webserver is configured to not pass the files to the relevant language processor then it doesn't matter which language it is, whether it's PHP, Perl, Python, ASP or any of them. Your total lack of understanding is the real eye-opener here.

It’s not bad

cookieMonster

I’ve used it for some small projects or internal tools, to prove a concept was workable or valid. But if I decided to develop the idea I went with RoR, mainly because I was lazy and rails provided all the scaffolding I needed to get the job done.

People often find it easier to be a result of the past than a cause of the
future.