What's new in PHP 8.5Written on 2025-11-20PHP 8.5 was released on November 20, 2025. It includes the pipe operator, clone with, a new URI parser, and more. PHP 8.5 introduces the new pipe operator that makes chaining output from one function to another a lot easier. Instead of deeply nested function calls like this: $input = ' Some kind of string. '; $output = strtolower( str_replace(['.', '/', '…'], '', str_replace(' ', '-', trim($input) ) ) ); You can now write this: $output = $input |> trim(...) |> (fn (string $string) => str_replace(' ', '-', $string)) |> (fn (string $string) => str_replace(['.', '/', '…'], '', $string)) |> strtolower(...); I've done a deep-dive into this new operator, and you can read about it here. There's now a way to assign new values to cloned objects while cloning them: final class Book { public function __construct( public string $title, public string $description, ) {} public function withTitle(string $title): self { return clone($this, [ 'title' => $title, ]); } } I think this is a great feature. The only thing I find unfortunate is that it doesn't work when cloning readonly properties from the outside (which I think is a common use case). To do so, you have to specifically reset the propery's write access to public(set). I explained the problem here. You can now mark a function with the #[NoDiscard] attribute, indicating that its return value must be used. If nothing happens with that return value, a warning will be triggered. #[NoDiscard("you must use this return value, it's very important.")] function foo(): string { return 'hi'; } foo(); $string = foo(); The warning can still be surpressed by using the new (void) cast: (void) foo(); Closures and first-class callables can now be used in constant expressions. In practice this means you'll be able to define closures in attributes, which is an incredible new feature: #[SkipDiscovery(static function (Container $container): bool { return ! $container->get(Application::class) instanceof Co...
First seen: 2025-11-20 07:02
Last seen: 2025-11-20 14:04