July 18, 2025

What’s New in PHP 8.5

Explore advanced PHP 8.5 features to write cleaner, safer, and more efficient code

Tutorial
What’s New in PHP 8.5

Introduction

PHP 8.5 is set to launch on November 20, 2025, bringing a wave of practical improvements that streamline daily coding, internationalization, configuration inspection, and debugging. In this article, we’ll unpack the newest additions and show how to apply them in real-world contexts.


1. Pipe Operator (|>)

The pipe operator enables a linear, intuitive way to feed values through a series of transforms:

$result = ' jane.doe@example.com ' |> trim(...) |> strtolower(...) |> ucfirst(...); // Result: "Jane.doe@example.com"

This pattern reduces nested calls and negates the need for temporary variables, improving readability and maintainability.


2. Final Property Promotion

You can now declare constructor-promoted properties as final, ensuring they remain immutable post-construction:

class ApiRequest { public function __construct( final string $endpoint, final array $payload ) {} }

This prevents subclasses, or later code, from altering these values, preserving the integrity of your models.


3. CLI Option: php --ini=diff

To quickly identify your custom PHP settings, php --ini=diff reveals only INI directives that deviate from the default configuration:

php --ini=diff ; Only custom settings shown memory_limit = "1G" upload_max_filesize = "100M"

Perfect for debugging environments or comparing setups.


4. Enforcing Return Value Usage (#[\NoDiscard])

Methods critical to program flow can now be marked so their return values must be used:

#[\NoDiscard("Must check status code")] function createTransaction(): TransactionResult { // ... } createTransaction(); // Warning: return value should not be ignored.

This helps avoid logic oversights where return values are unintentionally ignored.


5. Constants: Closures & Callables

Defining a constant as an anonymous function or callable reference is now supported:

class Formatter { public const TO_UPPER = fn(string $v): string => strtoupper($v); public const LOG = self::class . '::log'; }

This allows constants to hold reusable logic without relying on global functions or magic strings.


6. The PHP_BUILD_DATE Constant

A new built-in constant, PHP_BUILD_DATE, records the timestamp of your PHP build:

echo 'Compiled on: ' . date('Y-m-d H:i:s', PHP_BUILD_DATE);

Easily track which version is running and address deployment or environment issues.


7. array_first() and array_last()

Directly grab the first or last element of an array without resetting internal pointers:

$workflows = ['draft', 'review', 'publish']; array_first($workflows); // "draft" array_last($workflows); // "publish"

A small but welcome helper for cleaner, intention-revealing code.


8. IntlListFormatter

Locale-aware list formatting is now simplified with the IntlListFormatter class:

$fmt = new IntlListFormatter('en', IntlListFormatter::TYPE_AND); echo $fmt->format(['one','two','three']); // "one, two, and three"

Makes multilingual listing seamless and culturally aware.


9. Locale Direction Helpers

Detecting right-to-left text direction is simplified with:

if (locale_is_right_to_left('he')) { // Adjust UI alignment }

Or via the isRightToLeft method:

Locale::isRightToLeft('ar_EG');

Essential for properly designing RTL-friendly interfaces.


10. Getting Current Handlers

Fetch your active error or exception handlers to debug or extend them:

$prevHandler = get_exception_handler(); set_exception_handler(function ($e) use ($prevHandler) { log($e); $prevHandler && $prevHandler($e); });

Provides more control over error behavior in production.


Bonus Highlights

  • curl_multi_get_handles() gives access to all cURL handles in a multi-handle session.
  • Improved stack traces for fatal errors help debug deep problems.
  • Support for attributes on constants and asymmetric visibility adds further refinement.

Summary

PHP 8.5, expected on November 20, 2025, brings a suite of helpful improvements:

  • Cleaner code with pipe operator and final property promotion
  • Enforced return-value usage via attributes
  • Enhanced configuration inspection with --ini=diff
  • Better internationalization with new locale features
  • Smarter debugging through handler introspection

These updates collectively help you write cleaner, safer, and more reliable PHP code. Be ready to upgrade and take advantage of these enhancements!

Did you find this article helpful? Share it!