What is New in PHP 8.5
PHP 8.5 is a major release that introduces several powerful features, improves developer experience, and continues to strengthen type safety and performance. Below are the most important changes and additions.
Key New Features
Built-in URI Extension
A new core extension for parsing, normalizing, and building URLs according to RFC 3986 and the WHATWG URL specification.
Pipe Operator (|>)
Allows clean left-to-right function chaining. The value on the left is automatically passed as the first argument to the callable on the right.
$result = $input
|> trim(...)
|> htmlspecialchars(...)
|> strlen(...);
Clone With Syntax
Clone an object and modify selected properties in one expression. Especially useful with readonly classes.
$copy = clone $user with { $name = 'New Name', $active = true };
#[\NoDiscard] Attribute
Marks methods whose return value must not be ignored. Ignoring it triggers a compile-time warning.
#[\NoDiscard]
function compute(): int { ... }
array_first() and array_last()
Convenient helpers that return the first or last array element, or null if the array is empty.
$head = array_first($items) ?? 'default';
$tail = array_last($items);
Persistent cURL Share Handles
curl_share_init_persistent() creates share handles that survive across requests, reusing cookies, DNS cache, and connections automatically.
Other Notable Improvements
- Fatal errors now include a full backtrace.
- Attributes can target constants.
- #[\Override] attribute now works on properties.
- #[\Deprecated] attribute can be used on traits and constants.
- Static properties support asymmetric visibility.
- Constructor-promoted properties can be declared
final. - New
Closure::getCurrent()method simplifies recursive anonymous functions. setcookie()andsetrawcookie()support the "partitioned" attribute for CHIPS cookies.- New functions:
get_error_handler()andget_exception_handler(). - DOM gains
Element::getElementsByClassName()andinsertAdjacentHTML(). - New
grapheme_levenshtein()function. - Static closures and first-class callables are allowed in constant expressions.
Deprecations and BC Breaks
| Feature | Status / Change |
|---|---|
Backtick operator `...` |
Deprecated (alias of shell_exec()) |
| Non-standard casts | (boolean), (integer), (double), (binary) deprecated → use (bool), (int), (float), (string) |
disable_classes ini directive |
Removed |
| Case statement ending with semicolon | Deprecated (must use colon) |
Using null as array key or in array_key_exists() |
Deprecated |
class_alias() with "array" or "callable" as alias name |
No longer allowed |
__sleep() and __wakeup() |
Soft-deprecated → prefer __serialize() / __unserialize() |
Casting NAN to other types |
Now emits a warning |
Destructuring non-traversables with [] or list() |
Warning (except for null) |
| Casting floats that lose precision to int | Now emits a warning |
Final Thoughts
PHP 8.5 delivers cleaner syntax with the pipe operator and clone-with expression, stronger safety through new attributes and warnings, and useful helpers that reduce boilerplate. These changes make everyday coding more enjoyable while preparing the language for future improvements.