What's New in PHP 8.5?

By Maulik Paghdal

09 Nov, 2025

What's New in PHP 8.5?

Introduction

PHP 8.5 is here, and while it’s not a revolutionary update, it brings a bunch of meaningful improvements that developers will actually enjoy using. This version focuses on code readability, developer experience, and better debugging support - small things that make a big difference in day-to-day coding.

Let’s go through some of the most exciting changes in PHP 8.5 and see how they can improve your workflow.


The Pipe Operator (|>)

The new pipe operator might be one of the most discussed additions in PHP 8.5. It allows you to write cleaner and more readable function chains without deeply nested calls.

Before PHP 8.5

$result = htmlentities(strtoupper(trim(' Hello World '))); 

With PHP 8.5

$result = ' Hello World '  |> trim(...)  |> strtoupper(...)  |> htmlentities(...); 

The value from the left-hand side automatically gets passed as the first argument to the function on the right-hand side. This makes transformations flow naturally.

⚠️ Warning: Built-in functions that don’t accept parameters (like time()) can’t be used directly. You’ll need to wrap them in a closure if needed.


New Array Convenience Functions

PHP 8.5 finally adds two small but super useful helpers: array_first() and array_last().

Example:

$names = ['Alice', 'Bob', 'Charlie'];  echo array_first($names); // Alice echo array_last($names); // Charlie 

These functions make it easier to work with arrays without needing awkward combinations like reset() or array_slice().

📌 Usage Notes:

FunctionDescriptionExampleCommon Pitfall
array_first($array)Returns first value or null if emptyarray_first([])nullBe sure to check for null values
array_last($array)Returns last value or null if emptyarray_last(['a', 'b'])'b'Works only on sequential arrays

💡 Tip: These are ideal for cleaner loops, pagination, and when you need quick access to boundary elements.


Better Error and Exception Debugging

Ever faced a fatal error that gave you no clue where it came from? PHP 8.5 fixes that. It now provides stack traces for fatal errors, making debugging much easier.

You’ll also find two new functions:

get_error_handler(); get_exception_handler(); 

These let you inspect currently registered handlers - super useful for frameworks or custom error logging setups.

💡 Tip: Combine this with set_exception_handler() for custom error pages or centralized logging.


Closures and First-Class Callables in Constants

PHP 8.5 expands where you can use closures and callables - they now work in constant expressions.

Example:

class Formatter {  public const UPPER = static fn($str) => strtoupper($str);  public const LOWER = 'strtolower'(...); }  echo (Formatter::UPPER)('php'); // PHP 

This makes constants more dynamic and flexible, especially when you want to store callable behavior inside classes.

⚠️ Warning: You can’t use variable-capturing closures (no $this or local variables). Only static closures are allowed.


Final Property Promotion

A small but powerful improvement - you can now declare final promoted properties directly in the constructor.

Example:

class User {  public function __construct(  final public readonly string $name  ) {} } 

This ensures the property cannot be overridden by subclasses, helping enforce immutability and maintain predictable class design.

💡 Tip: Combine final and readonly for strict data models - perfect for DTOs (Data Transfer Objects).


Locale and Intl Enhancements

For developers dealing with multilingual apps, PHP 8.5 adds useful internationalization updates:

  • locale_is_right_to_left() - Checks if a locale uses right-to-left writing.
  • IntlListFormatter - Lets you format lists according to locale conventions.

Example:

$formatter = new IntlListFormatter('en', IntlListFormatter::TYPE_CONJUNCTION); echo $formatter->format(['Apples', 'Oranges', 'Bananas']); // Output: Apples, Oranges, and Bananas 

📌 Note: This is especially handy for apps with localization or dynamic user interfaces in multiple languages.


CLI and Configuration Improvements

Developers and DevOps folks will appreciate these:

  • PHP_BUILD_DATE - A new constant showing when PHP was built.
  • php --ini=diff - Displays differences from default INI settings.
  • max_memory_limit - A system-level directive to cap memory_limit.

💡 Tip: These additions make it easier to diagnose server environments and enforce safer memory policies.


cURL Extension: curl_multi_get_handles()

If you’ve ever worked with multiple cURL handles, you know it can get messy. PHP 8.5 adds:

curl_multi_get_handles($multiHandle); 

This lets you retrieve all handles from a multi-handle session, which helps when managing concurrent requests or debugging network code.

📌 Note: Useful in APIs or apps that make parallel requests, like fetching data from multiple microservices.


Deprecations to Watch Out For

Upgrades always come with a few warnings. Here’s what’s being deprecated in PHP 8.5:

DeprecatedReplacement / Notes
MHASH_* constantsUse hash_*() functions
Non-canonical casts like (boolean) or (double)Use (bool) or (float) instead
Returning non-string values from output handlersMust always return a string
Emitting output from custom output buffer handlersAvoid side-effects in handlers

⚠️ Warning: Audit older projects or libraries before upgrading. These deprecations may trigger warnings in legacy code.


Final Thoughts

PHP 8.5 isn’t about flashy new syntax or breaking paradigms-it’s about making our everyday development smoother. From the pipe operator to simpler array handling and better debugging, these small refinements add up to a much better experience.

If you’re already on PHP 8.2 or 8.3, upgrading should be straightforward. The key takeaway is: PHP is maturing gracefully, keeping modern features in check without losing its simplicity.

💡 Pro Tip: Start testing your applications with PHP 8.5 early using a dev environment or Docker image. That way, you’ll catch any deprecation warnings before deploying.


About Author

I'm Maulik Paghdal, the founder of Script Binary and a passionate full-stack web developer. I have a strong foundation in both frontend and backend development, specializing in building dynamic, responsive web applications using Laravel, Vue.js, and React.js. With expertise in Tailwind CSS and Bootstrap, I focus on creating clean, efficient, and scalable solutions that enhance user experiences and optimize performance.