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.
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.
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
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.
$input = ' Some kind of string. ';
$output = strtolower(
str_replace(['.', '/', '…'], '',
str_replace(' ', '-',
trim($input)
)
)
);
var_dump($output);
// string(19) "some-kind-of-string"
$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.
function getPhpVersion(): string {
return 'PHP 8.4';
}
getPhpVersion(); // No Errors
#[\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.
Better Performance
PHP 8.5 delivers improved performance with optimizations across the board.
JIT Compiler
Enhanced JIT compilation for better performance in compute-heavy tasks
Memory Usage
Optimized memory management for reduced footprint in web applications
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.
Windows
Pre-built binaries for Windows including thread-safe and non-thread-safe versions.
Windows DownloadsPackage 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