PHP php.net
Released November 21, 2024

A major update of the PHP language featuring the new URI extension, support for modifying properties while cloning, the Pipe operator, performance improvements, bug fixes, and general cleanup.

What's New

Key Features in PHP 8.5

Discover the powerful new features that make PHP 8.5 more expressive, performant, and developer-friendly.

Clone with

Support for modifying properties while cloning objects with a more concise syntax.

PHP 8.4 and earlier
final readonly class PhpVersion {
    public function __construct(
        public string $version = 'PHP 8.4',
    ) {}
    
    public function withVersion(string $version): self {
        $newObject = clone $this;
        $newObject->version = $version;
        return $newObject;
    }
}

$version = new PhpVersion();
var_dump($version->version);
// string(7) "PHP 8.4"

var_dump($version->withVersion('PHP 8.5')->version);
// Fatal error: Uncaught Error: Cannot modify readonly property PhpVersion::$version
PHP 8.5
final readonly class PhpVersion {
    public function __construct(
        public string $version = 'PHP 8.4',
    ) {}
    
    public function withVersion(string $version): self {
        return clone($this, [
            'version' => $version,
        ]);
    }
}

$version = new PhpVersion();
var_dump($version->version);
// string(7) "PHP 8.4"

var_dump($version->withVersion('PHP 8.5')->version);
// string(7) "PHP 8.5"

var_dump($version->version);
// string(7) "PHP 8.4"

Benefits: This new syntax allows modifying properties during cloning without requiring additional steps, making working with readonly classes more intuitive and less error-prone.

Pipe Operator

The Pipe operator provides a more readable way to chain function calls by passing the result of one expression as the first argument to the next function.

PHP 8.4 and earlier
$input = ' Some kind of string. ';

$output = strtolower(
    str_replace(['.', '/', '…'], '',
        str_replace(' ', '-',
            trim($input)
        )
    )
);

var_dump($output);
// string(19) "some-kind-of-string"
PHP 8.5 with Pipe Operator
$input = ' Some kind of string. ';

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

var_dump($output);
// string(19) "some-kind-of-string"

Benefits: The Pipe operator makes code more readable and easier to understand by clearly showing the data flow from one operation to the next, reducing nested function calls.

New #[\NoDiscard] Attribute

The #[\NoDiscard] attribute ensures that the return value of a function is either used or intentionally ignored, helping prevent bugs where return values are accidentally ignored.

PHP 8.4 and earlier
function getPhpVersion(): string {
    return 'PHP 8.4';
}

getPhpVersion(); // No Errors
PHP 8.5 with #[\NoDiscard]
#[\NoDiscard]
function getPhpVersion(): string {
    return 'PHP 8.5';
}

getPhpVersion();
// Warning: The return value of function getPhpVersion() should either be used or intentionally ignored by casting it as (void)

Benefits: This attribute helps catch potential bugs where function return values are accidentally ignored, improving code reliability and maintainability.

New URI Extension

RFC 3986 and WHATWG URL compliant API with new classes like Uri\Rfc3986\Uri and Uri\WhatWg\Url.

New array_first() and array_last()

Simplified array element retrieval with new built-in functions for common operations.

Additional Enhancements

Property Promotion for final classes, Attributes for constants, #[\Override] for properties, and more.

Performance

Better Performance

PHP 8.5 delivers improved performance with optimizations across the board.

Improved

JIT Compiler

Enhanced JIT compilation for better performance in compute-heavy tasks

Enhanced

Memory Usage

Optimized memory management for reduced footprint in web applications

Faster

Overall Execution

General performance improvements across various workloads

Continuous Optimization

The PHP core team continuously works on performance improvements. Actual performance gains depend on your specific use case, hardware, and application architecture. Always benchmark your own applications when upgrading.

Get PHP 8.5

Choose your preferred installation method and start using PHP 8.5 today.

Source

Download and compile from source for maximum control and customization.

Download Source

Windows

Pre-built binaries for Windows including thread-safe and non-thread-safe versions.

Windows Downloads

Package Managers

Install via Homebrew, apt, yum, or your preferred package manager.

brew install php@8.5
apt install php8.5

Migration Guide

Upgrading from an earlier version? Here's what you need to know about compatibility and breaking changes.

Deprecations

  • Various Minor Deprecations

    Several minor features have been deprecated in PHP 8.5. Check the full migration guide for details.

  • Function and Method Signatures

    Some internal function signatures have been updated for better type safety.

  • Extension Updates

    Several extensions have received updates that may require code adjustments.

Breaking Changes

  • Stricter Type Checking

    Enhanced type validation in internal functions for improved type safety.

  • Extension Compatibility

    Some third-party extensions may require updates to work with PHP 8.5.

  • Removed Features

    Features deprecated in earlier versions have been removed.

Upgrading Best Practices

Test thoroughly in a development environment before upgrading production systems

Review and address all deprecation notices in your codebase

Verify third-party package compatibility with PHP 8.5

Update your CI/CD pipelines to use PHP 8.5 for testing

Read Full Migration Guide