What's New and Changed in PHP 8.5

PHP 8.5 Photo by benjamincrozat.com

The PHP team is gearing up to release PHP 8.5 this November 2025. PHP 8.5 introduces many new features, developer-centric enhancements, and long-awaited cleanups. This version continues PHP’s trajectory toward a more modern, predictable, and introspectable runtime. While not a massive overhaul, this update packs several quality-of-life improvements that PHP developers have been waiting for.

What's New in PHP 8.5

max_memory_limit: A Ceiling for memory_limit

PHP 8.5 adds a new INI directive called max_memory_limit, designed to enforce an upper bound on the memory_limit setting. By default, it is set to -1, meaning no ceiling is applied unless explicitly configured. This directive is marked as INI_SYSTEM, which means it can only be set in system-level configuration files (e.g., php.ini) and cannot be changed at runtime.

This feature is particularly useful for shared hosting providers, containerized environments, and CI/CD pipelines where memory usage must be tightly controlled. If a script or configuration attempts to raise memory_limit above the defined max_memory_limit, PHP will emit a warning and cap the value accordingly.

IntlListFormatter: Locale-Aware List Formatting

The Intl extension gains a new class, IntlListFormatter, which enables developers to format lists in a way that respects the grammatical rules of the target locale. This includes conjunctions like "and", "or", and unit-based formatting. The class uses ICU (International Components for Unicode) data under the hood, ensuring consistency with other internationalized software stacks.

This is especially valuable for multilingual applications, e-commerce platforms, and content management systems that need to present lists naturally in different languages. For example:

$formatter = new IntlListFormatter('fr_FR', IntlListFormatter::TYPE_AND, IntlListFormatter::STYLE_STANDARD);
echo $formatter->format(['pommes', 'bananes', 'cerises']); // "pommes, bananes et cerises"

This mirrors native language expectations and improves UX for global audiences.

CLI: php --ini=diff for INI Diagnostics

PHP’s CLI now supports a new flag: php --ini=diff. This command outputs only the INI directives that differ from PHP’s built-in defaults. It’s a powerful diagnostic tool for developers and sysadmins who need to audit configuration changes across environments.

Unlike php --ini, which lists all loaded INI files, --ini=diff focuses on what’s been customized—making it ideal for debugging performance issues, memory leaks, or unexpected behavior due to misconfigured settings.

array_first() and array_last()

PHP 8.5 introduces two new functions—array_first() and array_last()—to retrieve the first and last values of an array, respectively. These are natural complements to array_key_first() and array_key_last() introduced in PHP 7.3.

These functions simplify common patterns in data processing, especially when working with associative arrays or datasets where positional access matters. They also return null for empty arrays, avoiding warnings or errors:

$data = ['name' => 'John', 'age' => 30];
echo array_first($data); // 'John'
echo array_last($data);  // 30

Internally, these functions use the same logic as accessing $array[array_key_first($array)], but with cleaner syntax and better readability.

locale_is_right_to_left() and Locale::isRightToLeft()

To support better internationalization, PHP 8.5 adds two new ways to detect whether a given locale uses a right-to-left (RTL) script. This includes languages like Arabic, Hebrew, and Urdu. The functions use ICU data to stay up-to-date with global standards.

locale_is_right_to_left('ar'); // true
Locale::isRightToLeft('en');   // false

This is especially useful for rendering UI components, adjusting layout direction, and applying correct text alignment in multilingual applications.

Stack Traces for Fatal Errors

Historically, PHP fatal errors would terminate execution without providing a stack trace, making debugging difficult. PHP 8.5 changes that by including stack traces for unrecoverable errors such as memory exhaustion or illegal operations.

This enhancement brings fatal errors closer to exception behavior, allowing developers to trace the origin of the issue more effectively. It’s a major win for debugging production crashes and improving error visibility in logs.

get_error_handler() and get_exception_handler()

PHP has long allowed developers to set custom error and exception handlers using set_error_handler() and set_exception_handler(). However, until now, there was no way to inspect the currently active handlers.

PHP 8.5 introduces get_error_handler() and get_exception_handler() to retrieve the current callable or null if none is set. This is particularly useful for frameworks, middleware, and debugging tools that need to wrap or restore handlers without breaking existing behavior.

PHP_BUILD_DATE Constant

A new constant, PHP_BUILD_DATE, exposes the exact timestamp when the PHP binary was compiled. This complements existing constants like PHP_VERSION and PHP_VERSION_ID, and is useful for auditing deployments, debugging version mismatches, and tracking build provenance across environments.

Curl: curl_multi_get_handles()

The Curl extension adds curl_multi_get_handles(), a function that returns all CurlHandle objects currently managed by a CurlMultiHandle. This improves introspection and control over multi-request workflows, especially in asynchronous or concurrent HTTP operations.

It complements existing functions like curl_multi_add_handle() and curl_multi_remove_handle(), and is ideal for debugging or dynamically managing request pools.

Pipe Operator (|>)

PHP 8.5 introduces the pipe operator (|>), which allows chaining callables in a readable, left-to-right syntax. It passes the result of one expression as the first argument to the next, reducing nesting and improving clarity.

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

This is equivalent to nested calls like trim(str_shuffle(strtoupper(...))), but far easier to read and maintain. The operator works with functions, closures, and first-class callables, though it has some limitations: it only supports single-argument callables and doesn’t work with by-reference parameters.

Deprecations in PHP 8.5

Output from Custom Buffer Handlers

PHP’s ob_start() function allows developers to define custom output buffer handlers. However, if these handlers emit output directly (e.g., via echo or print), that output was previously ignored silently. PHP 8.5 now emits a deprecation warning when this occurs.

This change enforces cleaner separation of concerns and encourages developers to return processed strings from buffer handlers instead of side-effect output.

Non-String Returns from Buffer Handlers

Custom output buffer handlers must return strings. PHP 8.5 enforces this by emitting a deprecation notice when a non-string value is returned. This aligns with the documented behavior and prevents unexpected coercion or silent failures.

Non-Canonical Scalar Casts

PHP has historically allowed multiple names for scalar type casts, such as (boolean) and (bool), or (integer) and (int). PHP 8.5 deprecates the non-canonical forms:

  • (boolean) → use (bool)
  • (double) → use (float)
  • (integer) → use (int)
  • (binary) → use (string)

This cleanup improves consistency and simplifies parsing for tools and static analyzers.

MHASH_* Constants

The mhash extension was deprecated in PHP 8.1, but its constants remained available. PHP 8.5 completes the deprecation by removing all MHASH_* constants. Developers should migrate to the hash extension, which provides modern and secure hashing algorithms like SHA-256, SHA-3, and HMAC.

Final Thoughts

PHP 8.5 prioritizes developer experience, runtime introspection, and internationalization. Whether you're building scalable web platforms, managing hosting environments, or crafting multilingual interfaces, this version offers practical tools and cleaner semantics.

For a full list of RFCs and implementation notes, visit PHP.Watch’s PHP 8.5 overview.

Related articles

Elsewhere

Discover our other works at the following sites: