PHP 8 logo php.net

PHP 8 Keeps Open-Source Programming Language Moving Forward

The first major update of the widely deployed PHP web programming language in years brings new features that could help expand its adoption and usage.

In the beginning of the web era, the open-source PHP programming language was at the core of all web development and, with its new 8.0 release, is trying to become more relevant for a new generation of developers.

First released 25 years ago, PHP is the "P" in the LAMP (Linux, Apache, MySQL, PHP) stack that defined the first generation of web development. In recent years, other languages, including Python and JavaScript, have exceeded PHP's popularity, while upstart languages such as Go and Rust are growing quickly too.

However, PHP has not been sitting idle as other languages grow. PHP 8.0, which became generally available on Thanksgiving Day (Nov. 26), integrates a series of new capabilities, including a just-in-time (JIT) compilation engine that accelerates performance over prior PHP releases.

Other improvements include language optimizations that will benefit developers, including named arguments and attributes.

"PHP remains one of the most common scripting languages today," James Owen, senior analyst at Evans Data, told ITPro Today.

The Love/Hate Relationship with PHP

According to Evans Data's Global Development Survey 2020, v1, 79% of users of scripting language use PHP for some portion of their scripting language efforts.

"Despite some variation over the years, this use rate has remained quite flat among scripting language users," Owen said.

PHP usage ranks differently across various industry surveys. The June 2020 RedMonk Programming Language Rankings report has PHP in the No. 4 slot, behind JavaScript, Python and Java. The TIOBE Index of programming language popularity isn't as generous to PHP, ranking it 8th in its November 2020 listing.

Stack Overflow also ranks PHP as the eighth most used language, but it also gives PHP the dubious distinction of being the sixth most dreaded language.

PHP was created by developer Rasmus Lerdorf in 1995, and the project has since benefited from a large community of contributors. One of leading contributors and commercial supporters of PHP over the past two decades is developer tools company Zend, which is now part of Perforce Software.

"People are congratulating me on PHP 8. That is completely misdirected," Lerdorf wrote in a Twitter message last week. "@nikita_ppv [Nikita Popov from Jetbrains] and @dstogov [Dmitry Stogov from Zend] have been the driving forces behind PHP for years now. Countless others pitch in regularly as well. PHP 8 is significantly better because it contains a lot less of my code."

What Features Developers Will Notice in PHP 8

PHP was created as a web-centric language, Matthew Weier O'Phinney, product manager for Zend, told ITPro Today. Since data is submitted to websites via forms, it all comes in as strings, which means PHP has tended toward what is known as "loose typing" and "type coercion" where code can make assumptions about what was submitted. While loose typing can be helpful, O'Phinney said it also leads to errors and potential security issues.

When PHP 7.0 was released in 2015, a number of opt-in feature were added to the language to enable strict typing; with PHP 8.0, those features are being expanded. PHP 8 provides what are known as "union types" — a way to indicate that an argument or return value can be one of a set of types, O'Phinney said.

"When it comes to developer experience improvements, the language is adding several features that will simplify common patterns," he said.

One of those common patterns is around the practice of using a class constructor to assign class properties from arguments provided to it. In previous PHP releases, O'Phinney said developers had to declare the properties, then declare arguments in the class constructor for each, and then perform the actual assignments of the arguments to the properties. A new feature called "class constructor property promotion" does this all in one operation by defining the properties from the arguments using a special syntax.

PHP 8.0 also gains an attributes system that O'Phinney said has been a long time in the making. Many languages have "attribute" or "annotation" systems that allow developers to define metadata about code artifacts, he said. These have been used by things such as object relational mappers to allow mapping properties of a class to columns in a database, or to map a web server path to the code that will handle it. PHP has had libraries for performing such things, but PHP 8 now adds an attributes system that bakes it directly into the language.

PHP 8 Comes Just in Time

The new just in time (JIT) compiler in PHP 8.0 could well help broaden adoption of PHP.

"JIT is fantastic for numerical calculations and things that are computationally expensive," O'Phinney said. "However, PHP is generally used for web applications, which are neither."

He noted that PHP tends to be input/output (I/O) bound where performance is impacted primarily by things like querying a database, caching values, sending API requests or accessing the filesystem. What JIT will do, however, is open the door for PHP to be used in more computationally intensive applications.

"PHP celebrated its 25th birthday this past month, and has seen eight major releases, and is still responsible for the lion's share of what is deployed on the internet," O'Phinney said. "It is a stable, mature language that is constantly evolving, receiving features such as JIT that will allow it to reach into ecosystems previously dominated by other languages such as ML [machine learning], and because of the ease with which one can deploy it and the low barrier to entry for developers, it's not going away. If anything, look for PHP to continue growing."

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish