Tech Verse Logo
Enable dark mode
PHP 8.5 New Features and Deprecations

PHP 8.5 New Features and Deprecations

Tech Verse Daily

Tech Verse Daily

4 min read

Hey PHP developers! 2025 is shaping up to be an exciting year for the PHP ecosystem. After a long wait, PHP 8.5 is finally landing this November with some seriously cool features we’ve been asking for. Let’s dive into what’s coming!

What’s New in PHP 8.5

1. Pipe Operator (|>) - The Star of the Show!

This is the feature everyone’s been waiting for! The pipe operator lets you chain multiple callables from left to right, taking the return value from the left callable and passing it to the right one.

Before PHP 8.5, if you wanted to perform a series of operations on data, you had to write code like this:

// Method 1: Nested function calls that hurt your eyes
$result = trim(str_shuffle(strtoupper("Hello World")));

// Method 2: Using temporary variables (verbose and messy)
$result = "Hello World";
$result = strtoupper($result);
$result = str_shuffle($result);
$result = trim($result);

With the pipe operator in PHP 8.5, the code above becomes much more elegant:

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

// Output: "LWHO LDLROE"

Data flows from left to right in a more natural and readable way. No more confusion with nested functions or creating temporary variables that are only used once.

Practical example for creating slugs:

$input = ' Some kind of string. ';

$slug = $input 
    |> trim(...) 
    |> fn (string $s) => str_replace(' ', '-', $s) 
    |> fn (string $s) => str_replace(['.', '/', '…'], '', $s) 
    |> strtolower(...);

// Output: "some-kind-of-string"

The (...) notation next to the function name makes it a first-class callable, a feature that's been available since PHP 8.1.

Important things to note:

  • All callables MUST accept only one required parameter. If you need additional parameters, use closures or arrow functions.

  • The pipe operator evaluates from left to right, unless you change the order with parentheses ().

  • Functions with a void return type can be used, but must be in the last position since they don't return a value.

The pipe operator is considered one of the highest “bang for the buck” features in recent memory, on par with constructor property promotion.

2. array_first() and array_last() Functions

Finally! These simple yet incredibly useful features are now native in PHP 8.5.

Previously, to get the first or last element of an array, you had to use tricks like reset() and end() which modify the array's internal pointer, or use more complicated approaches like $array[array_key_first($array)].

Now, with PHP 8.5, everything becomes easier:

$numbers = [1, 2, 3, 4, 5];
$first = array_first($numbers);  // 1
$last = array_last($numbers);    // 5

// Works with associative arrays
$colors = ['apple' => 'red', 'orange' => 'orange', 'banana' => 'yellow'];
$first = array_first($colors);  // "red"
$last = array_last($colors);    // "yellow"

// Empty array? No problem!
$empty = [];
$first = array_first($empty);  // null
$last = array_last($empty);    // null

Both functions return the first or last value from an array without modifying the internal pointer. This makes your code safer and more predictable.

Benefits of using these functions:

  • Doesn’t modify the array’s internal pointer

  • Easier to read and understand

  • Works with all array types (indexed, associative, etc.)

  • Returns null for empty arrays without warnings

3. get_exception_handler() and get_error_handler() Functions

PHP has long allowed setting custom error and exception handlers, but until PHP 8.5, there was no direct way to retrieve the currently active handler.

Before PHP 8.5, if you wanted to know the active error handler, you had to do an awkward workaround:

// Old convoluted way
$current = set_error_handler('var_dump');
restore_error_handler();
var_dump($current);

Now in PHP 8.5:

// New simple way
$errorHandler = get_error_handler();      // ?callable or null
$exceptionHandler = get_exception_handler();  // ?callable or null

These functions return the currently active callable, or null if no custom handler is installed.

Practical use case:

// Set error handler
function primaryErrorHandler(int $errno, string $errstr): void {
    echo "[Primary] $errstr\n";
}
set_error_handler('primaryErrorHandler');

// Wrap with logging
$previous = get_error_handler();
set_error_handler(function($errno, $errstr, $errfile, $errline) use ($previous) {
    file_put_contents(__DIR__.'/error.log', "$errstr\n", FILE_APPEND);
    
    if ($previous) {
        call_user_func($previous, $errno, $errstr, $errfile, $errline);
    }
});

This way, you can chain and wrap handlers more easily and safely.

4. Stack Trace Support for PHP Fatal Errors

When a fatal error occurs in PHP 8.5, you’ll now get a more informative stack trace. This is extremely helpful for debugging, especially when production applications encounter issues.

5. locale_is_right_to_left() Function and Locale::isRightToLeft() Method

For those developing multilingual applications or working with right-to-left languages (like Arabic or Hebrew), this feature will be incredibly helpful. You can now easily check if a locale uses RTL (Right-to-Left) writing systems.

6. curl_multi_get_handles() - New Curl Function

This new function makes it easier to retrieve all active handles in a curl multi session. Super useful when working with multiple concurrent HTTP requests.

7. New PHP_BUILD_DATE Constant

There’s now a new constant that provides information about when your PHP version was built. Useful for logging and debugging purposes.

8. CLI: php --ini=diff

A practical new CLI feature! You can now see which INI directives differ from default values by running:

php --ini=diff

This is extremely helpful when troubleshooting PHP configuration across different environments.

9. Intl: New IntlListFormatter Class

A new class for formatting lists according to specific locales. For example, “A, B, and C” in English becomes “A, B et C” in French.

10. New max_memory_limit INI Directive

This new directive allows you to set a ceiling for memory_limit. So even if a script tries to change memory_limit, it won't be able to exceed the limit you set in max_memory_limit.

Deprecations in PHP 8.5

Every new PHP version inevitably deprecates some old features. It’s important to know about these so you can prepare your application code.

1. All MHASH_* Constants Deprecated

In PHP 8.1, mhash functions were already deprecated, but the constants remained available. In PHP 8.5, all MHASH_* constants are also deprecated.

Recommended migration:

// Old way (deprecated)
$hash = mhash(MHASH_SHA1, 'test');

// New way
$hash = hash('sha1', 'test', true);

The hash() function accepts a string value for the algorithm name, and by default returns the hash as a hex value unless the third parameter is set to true.

2. Non-Canonical Scalar Type Casts Deprecated

PHP has long allowed several variations for scalar type casting. For example, you could cast to integer using either (integer) or (int), and both were valid.

In PHP 8.5, these non-canonical forms are deprecated:

  • (boolean) → use (bool)

  • (integer) → use (int)

  • (double) → use (float)

  • (binary) → use (string)

Update your code:

// Deprecated
$value = '42';
$int = (integer) $value;
$float = (double) $value;
$bool = (boolean) $value;

// Use canonical forms
$int = (int) $value;
$float = (float) $value;
$bool = (bool) $value;

This change improves consistency and makes parsing easier for tools and static analyzers.

3. Returning Non-String Values from User Output Handler

If you’re using custom output handlers, make sure your function always returns a string. Return values other than strings are now deprecated and will cause errors in PHP 9.0.

4. Emitting Output from Custom Output Buffer Handlers

Custom output buffer handlers shouldn’t directly emit output. This behavior is now deprecated to avoid confusion and unpredictable behavior.

Preparing for PHP 8.5

Although PHP 8.5 won’t be released until November 2025, you can start preparing your applications now:

1. Audit Deprecated Code

Search your codebase for any usage of:

  • MHASH_* constants

  • Non-canonical type casts like (integer), (boolean), (double), (binary)

  • Custom array_first() or array_last() functions that might conflict with the new native functions

2. Update Testing Environment

If you’re adventurous, try installing PHP 8.5 RC in your development environment for testing. This will help you discover potential issues earlier.

3. Learn the Pipe Operator

Start getting familiar with the pipe operator because it’s going to change how you write PHP code. User-space pipe solutions suffer from performance overhead due to extra function calls and closures, while the native operator eliminates this overhead and allows compiler optimizations.

4. Review Error Handling

If you have custom error or exception handlers, leverage the new get_error_handler() and get_exception_handler() functions to make your error handling more robust.

Wrapping Up

PHP 8.5 brings many improvements focused on developer experience. This version prioritizes developer experience, runtime introspection, and internationalization.

Of all the new features, the pipe operator is the most game-changing. It makes your PHP code more readable, maintainable, and adopts functional programming patterns that are already popular in other languages.

The array_first() and array_last() functions may seem simple, but they solve a long-standing pain point in PHP. Same goes for get_error_handler() and get_exception_handler(), which make error handling more transparent.

The deprecations are also good steps toward cleaning up the language and improving consistency. While they may require some effort to update your code, the result will be worth it for a cleaner and more maintainable codebase.

So, are you ready to welcome PHP 8.5? Start preparing your applications now so when it’s released, you can upgrade right away without issues!

References:

    Latest Posts

    View All

    React 19: What’s new in React 19

    React 19: What’s new in React 19

    Laravel Strict Validation: Enforcing Exact PHP Types

    Laravel Strict Validation: Enforcing Exact PHP Types

    Next.js 16.0.1: The Essential Update Developers Shouldn’t Skip

    Next.js 16.0.1: The Essential Update Developers Shouldn’t Skip

    Time Interval Helpers in Laravel 12.40

    Time Interval Helpers in Laravel 12.40

    From GitHub Actions to Production Rollout: CI/CD for Laravel

    From GitHub Actions to Production Rollout: CI/CD for Laravel

    Top React Libraries and Frameworks Every Frontend Developer Should Know

    Top React Libraries and Frameworks Every Frontend Developer Should Know

    PHP 8.5 New Features and Deprecations

    PHP 8.5 New Features and Deprecations

    Manage, Track and Monitor Queue Jobs in Laravel with Vantage

    Manage, Track and Monitor Queue Jobs in Laravel with Vantage

    Tinkerwell 5: Introducing Tinkerwell Intelligence

    Tinkerwell 5: Introducing Tinkerwell Intelligence

    Roach PHP - Complete Web Scraping toolkit for PHP

    Roach PHP - Complete Web Scraping toolkit for PHP