Home

PHP 8.5 lays down long-awaited pipe operator, adds new URI tools

PHP 8.5 landed on Thursday with a long-awaited pipe operator and a new standards-compliant URI parser, marking one of the scripting language's more substantial updates.

PHP, short for Personal Home Page when initially released in 1995 by Rasmus Lerdorf, now stands for PHP: Hypertext Preprocessor. Version 8.5 is a major release that brings with it a handful of useful new capabilities. It follows PHP 8.4, which debuted a year ago.

Chief among these is the addition of a pipe operator.

"I don't think it's immodest to say that the pipe operator has one of the highest 'bangs for the buck' of any feature in recent memory, alongside such niceties as constructor property promotion," wrote Larry Garfield, a member of the PHP-FIG (framework interop group) core committee, back in July.

The pipe operator allows function calls to be chained together, which avoids the extraneous variables and nested statements that might otherwise be involved. Pipes tend to make code more readable than other ways to implement serial operations.

Anyone familiar with the Unix/Linux command line or programming languages like R, F#, Clojure, or Elixir may have used the pipe operator. In JavaScript, aka ECMAScript, a pipe operator has been proposed, though there are alternatives like method chaining.

Another significant addition is the URI extension, which allows developers to parse and modify URIs and URLs based on both the RFC 3986 and the WHATWG URL standards. Parsing with URIs and URLs – reading them and breaking them down into their different parts – is a rather common task for web-oriented applications. 

Yet prior versions of PHP didn't include a standards-compliant parser in the standard library. As noted by software developer Tim Düsterhus, the parse_url() function that dates back to PHP 4 doesn't follow any standard and comes with a warning that it should not be used with untrusted or malformed URLs.

Other noteworthy additions to the language include: Clone With, for updating properties more efficiently; the #[\NoDiscard] attribute, for warning when a return value goes unused; the ability to use static closures and first-class callables in constant expressions; and persistent cURL handles that can be shared across multiple PHP requests.

Code written in PHP generally relies on an interpreter, like the Zend Engine, that runs on a web server rather than being compiled into binary files. It can interface with third-party tools such as databases and output dynamically-generated web content in HTML or other languages.

PHP serves as the basis for WordPress, which accounts for about 43 percent of all websites, and for the Laravel web application development framework.

As for its popularity, PHP is either in decline or stable, depending upon which JetBrains survey one consults. It presently ranks 16th in the Tiobe Programming Language Index, down from 12th a year ago. ®

Source: The register

Previous

Next