PHP 8.5 Released, What’s New?

It’s that time again for the Santa ElePHPhant to visit all the good little developers around the world and shower them with new goodies that make it easier for them to build the web.

As of today, PHP 8.5.0 is in release status. It is a major update of the Hypertext Preprocessor language, with new features including the URI extension, Pipe operator, and support for modifying properties while cloning.

Overview

Key Features in PHP 8.5

URI Extension

The new always-available URI extension provides APIs to securely parse and modify URIs and URLs according to the to the RFC 3986 and the WHATWG URL standards. Powered by the uriparser (RFC 3986) and Lexbor (WHATWG URL) libraries. Learn more about the backstory of the URI extension in The PHP Foundation’s blog.

Pipe Operator

The |> operator allows chaining function calls together without dealing with intermediary variables. The pipe operator enables replacing many “nested calls” with a chain that can be read forwards, rather than inside-out. Learn more about the backstory of the pipe operator in The PHP Foundation’s blog.

Clone With

It is now possible to update properties during object cloning by passing an associative array to the clone() function. This enables straightforward support of the “with-er” pattern for readonly classes.

#[\NoDiscard] Attribute

By adding the #[\NoDiscard] attribute to a function, PHP will check whether the returned value is consumed and emit a warning if it is not. This allows improving the safety of APIs where the returned value is important, but it’s easy to forget using the return value by accident. The associated (void) cast can be used to indicate that a value is intentionally unused.

Closures and First-Class Callables in Constant Expressions

Static closures and first-class callables can now be used in constant expressions. This includes attribute parameters, default values of properties and parameters, and constants.

Persistent cURL Share Handles

Unlike curl_share_init(), handles created by curl_share_init_persistent() will not be destroyed at the end of the PHP request. If a persistent share handle with the same set of share options is found, it will be reused, avoiding the cost of initializing cURL handles each time. 

The array_first() and array_last() functions

These two new functions are added to ext-standard, where array_key_first() and array_key_last() functions return the first or last value of an array, respectively. If the array is empty, null is returned (making it easy to compose with the ?? operator).

Additional features and improvements – Deprecations and backward compatibility breaks

Upgrade to PHP 8.5

Our high-performance cloud hosting can test if your website is ready for PHP 8.5. To improve your hosting performance, upgrade your PHP version used, service or maintain your site, and purchase packages, please contact us.


Discover more from SEO Services Bristol

Subscribe to get the latest posts sent to your email.

Leave a Comment, Share Your Thoughts!