What’s New in PHP 8.5? Exploring Pipe Operator, NoDiscard, and Performance Boosts

PHP 8.5, released on November 20, introduces major enhancements such as the pipe operator, NoDiscard attribute, first‑class callable support in constant expressions, new array_first/array_last functions, persistent cURL handles, improved error tracing, and notable performance gains demonstrated in SVG generation benchmarks.

21CTO
21CTO
21CTO
What’s New in PHP 8.5? Exploring Pipe Operator, NoDiscard, and Performance Boosts

PHP 8.5 was officially released on 20 November and brings a set of significant language and standard library enhancements for backend developers.

Pipe operator – The new |> operator enables left‑to‑right function chaining, simplifying transformations. Example:

<?php
$result = "PHP Rocks"
    |> htmlentities(...)
    |> str_split(...)
    |> (fn($x) => array_map('strtoupper', $x))
    |> (fn($x) => array_filter($x, fn($v) => $v != '0'));
echo $result, PHP_EOL;

$temp = "PHP Rocks";
$temp = htmlentities($temp);
$temp = str_split($temp);
$temp = array_map('strtoupper', $temp);
$temp = array_filter($temp, fn($v) => $v != '0');
$result = $temp;
echo $result, PHP_EOL;

NoDiscard attribute – Marks a function’s return value as mandatory; ignoring it requires an explicit (void) cast, improving API predictability.

Constant expressions now accept static closures and first‑class callable objects, allowing constructs such as default property values or attribute parameters to embed concise validation logic.

The standard library adds utility functions array_first() and array_last(), persistent cURL handles for DNS and connection reuse, and enhanced fatal‑error backtraces with new error‑query functions.

Several legacy features are deprecated, including the back‑tick alias for shell_exec, non‑standard type‑cast names, and certain magic methods.

Performance tests show noticeable speed improvements, for example when generating SVG charts for articles, demonstrating PHP 8.5’s efficiency gains.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PHPPipe Operatorphp8.5new-features
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.