PHP 8.5 has been released with a long-awaited pipe operator and a new URI parser that adheres to RFC 3986 and WHATWG standards. The update includes additional features like Clone With, the #[\NoDiscard] attribute, static closures, and persistent cURL handles.
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 UR, and reading and breaking down URLs into their different parts, is a 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.
The release of PHP 8.5 is expected to streamline development processes for web developers, particularly those working on large-scale applications that require handling complex data structures and URL manipulations. The inclusion of a standards-compliant URI parser is a significant improvement over previous versions, addressing long-standing issues with URL parsing in PHP.