PHP 8.5 Introduces URI Extension, Pipe Operator, and Syntax Improvements

PHP 8.5 introduces a new URI extension, the pipe operator, and key syntax upgrades, delivering faster performance and cleaner code.

PHP, a server-side programming language used mainly for building dynamic websites and web applications, has just released version 8.5, a major update that adds new syntax, expanded attribute support, performance improvements, and multiple RFC-driven features.

One of the most significant additions is the new built-in URI extension. It provides a consistent API for parsing and modifying URLs, following both RFC 3986 and the WHATWG URL standards. Backed by uriparser and Lexbor, it replaces parse_url() in scenarios where accurate, standards-compliant handling is required.

Another major highlight of this version is the introduction of the pipe operator (|>), which enables left-to-right function chaining. This eliminates deeply nested function calls, making transformation pipelines easier to read and maintain. Values move directly through callables, including arrow functions and partial applications such as trim(...).

PHP 8.5 also improves object handling with clone-with syntax. Developers can now update selected properties while cloning an object through clone($obj, ['prop' => value]), simplifying the “with-er” pattern and making it usable in readonly classes without boilerplate.

Another addition is the #[\NoDiscard] attribute, which issues a warning when a function’s return value is ignored unintentionally. This helps catch mistakes in APIs where a returned value is required for correct behavior, with (void) available when the developer explicitly chooses to discard it.

The language also expands support for compile-time expressions. Static closures and first-class callables are now allowed in constant expressions, making them usable in attribute arguments, default property values, and class constants.

Performance-related improvements include persistent cURL share handles. With curl_share_init_persistent(), share handles survive across requests and reuse previously initialized connection data, reducing overhead in repeated network operations for long-running applications.

Two new helper functions, array_first() and array_last(), offer clearer handling for common cases. Both return null for empty arrays, which simplifies composition with the null-coalescing operator and removes the need for manual key checks.

Additional changes cover a broad set of language features. Fatal errors now include backtraces, attributes can target constants, and static properties support asymmetric visibility.

Properties can be marked as final via constructor property promotion. Plus, PHP also adds new DOM methods such as getElementsByClassName() and insertAdjacentHTML(), along with new utility functions like grapheme_levenshtein().

Finally, deprecations in PHP 8.5, include removal of non-canonical cast names, deprecation of the backtick operator as an alias for shell_exec(), warnings for invalid float-to-int casts, and limits on using null as an array offset. The older __sleep() and __wakeup() serialization methods are now soft-deprecated in favor of __serialize() and __unserialize().

For more information on all changes in PHP 8.5, refer to the official release announcement or to this page.

Bobby Borisov

Bobby Borisov

Bobby, an editor-in-chief at Linuxiac, is a Linux professional with over 20 years of experience. With a strong focus on Linux and open-source software, he has worked as a Senior Linux System Administrator, Software Developer, and DevOps Engineer for small and large multinational companies.

Leave a Reply

Your email address will not be published. Required fields are marked *