| PHP 8.5 Adds URI Extension |
| Written by Kay Ewbank | |||
| Friday, 12 December 2025 | |||
|
PHP 8.5 has been released with an extension supporting secure URI and URL parsing, a new a pipe operator and persistent cURL handles. PHP began life as a simple scripting language designed to build web pages but has developed into a general server side web language . It is now used for eight out of ten websites using server-side code.
The first improvement is a new always-available URI extension that provides APIs to Closures and First-Class Callables in Constant Expressions. The extension means that 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. The addition allows developers to securely parse and modify URIs and URLs according to the RFC 3986 and the WHATWG URL standards. Despite the importance of correctly parsing URLs, PHP hasn't until now included any standards-compliant parser within the standard library. There is the parse_url function, but it does not follow any standard and is explicitly documented not to be used with untrusted or malformed URLs. Developers have used this in place of any better alternative that is readily available, but while it works reasonably correctly for a majority of well-formed inputs that developers encounter in day-to-day work, it can still fail. The new extension provides standards-compliant parsers for both RFC 3986 and the WHATWG URL standard as an always-available part of its standard library. The PHP team says that not only will this enable easy, correct, and secure parsing of URLs according to the respective standard, but the URI extension also includes functionality to modify individual components of a URL. The second addition is a NoDiscard attribute, which when added to a function means that 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. PHP now finally has a Pipe operator, so allowing the chaining of function calls together without dealing with intermediary variables. This enables replacing many "nested calls" with a chain that can be read forwards, rather than inside-out. A new "Clone With" fproperty means developers can now 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. Another improvement means that cURL share handles are now persistent. This means that 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 final improvement of not is the addition of array_first() and array_last() functions. These 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). PHP 8.5 is available for download now.
More InformationRelated ArticlesPHP - Essential But Underappreciated PHP 8.0 Adds Metadata To Classes To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.
Comments
or email your comment to: comments@i-programmer.info |


