PHP 8.5: The Pipe Operator, Clone With, and Fresh Features

PHP 8.5

PHP 8.5: The Pipe Operator, Clone With, and Fresh Features

June 26, 2026
author: ماهان
no comment

PHP 8.5 was officially released on November 20, 2025, and it ranks among the richest releases of the language in recent years. Beyond performance improvements, it introduces several important language features that meaningfully improve code quality and readability. In this article we review the most important changes in PHP 8.5 with practical examples.

The Pipe Operator (|>)

The headline feature of this release is the pipe operator. It lets you pass the output of one function to the next in a left-to-right chain, without intermediate variables and without deeply nested calls. The result is more readable code that feels closer to the functional programming style.

// Old, nested style
$result = array_sum(array_map(fn($n) => $n * 2, array_filter($numbers, fn($n) => $n > 0)));

// With the pipe operator in PHP 8.5
$result = $numbers
    |> fn($arr) => array_filter($arr, fn($n) => $n > 0)
    |> fn($arr) => array_map(fn($n) => $n * 2, $arr)
    |> array_sum(...);

Clone With

Previously, modifying a readonly object after cloning was awkward. In 8.5, the new clone() syntax lets you update property values at the same time you clone an object. This makes implementing the “with-er” pattern on immutable classes much simpler.

final class Money {
    public function __construct(
        public readonly int $amount,
        public readonly string $currency,
    ) {}
}

$price = new Money(1000, 'IRR');
$discounted = clone($price, ['amount' => 800]);

The Built-in URI Extension

One of PHP’s long-standing gaps was the lack of a standard tool for parsing and normalizing URIs. PHP 8.5 introduces a built-in URI extension that follows the RFC 3986 and WHATWG URL standards, so you no longer need manual implementations or third-party packages to work with URLs.

The #[\NoDiscard] Attribute

This new attribute lets you mark functions or methods whose return value should probably not be ignored. If the caller doesn’t use the returned value, a warning is emitted. It’s very useful for designing safer APIs.

#[\NoDiscard("The result of this operation should be checked")]
function saveToDatabase(array $data): bool {
    // ...
    return true;
}

saveToDatabase($data); // Warning: return value was discarded

New Array Functions

Two widely requested functions, array_first() and array_last(), were added to retrieve the first and last value of an array. They complement array_key_first() and array_key_last() introduced in PHP 7.3, so you no longer need tricks like reset() and end().

$users = ['ali', 'sara', 'reza'];
echo array_first($users); // ali
echo array_last($users);  // reza

Closures in Constant Expressions

Static closures and first-class callables can now be used in constant expressions, including attribute parameters. This change adds flexibility to class metadata.

Other Improvements

Several important infrastructure changes also appear in this release. First, OPcache is now always compiled in, which means performance optimization is enabled by default. Second, backtraces for fatal errors have been added: with the new fatal_error_backtraces INI setting, a full call-stack trace is attached to fatal errors, making debugging far easier. This feature also respects the #[\SensitiveParameter] attribute so sensitive data isn’t leaked into logs.

Conclusion

PHP 8.5 is a smart blend of modern language features and infrastructure improvements. The pipe operator and clone-with improve readability, the URI extension and new array functions cover everyday needs, and always-on OPcache together with fatal-error backtraces improve both the development experience and performance. If you work on Laravel or plain PHP projects, upgrading to this version is well worth serious consideration—though before updating production, always verify dependency compatibility and run your automated tests.

write comment

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