The future of PHP starts now. Faster. Cleaner. Powerful.
PHP 8.5 introduces game-changing features that revolutionize how you write modern PHP applications.
New URI extension for modern URL parsing
$components = parse_url("https://php.net/releases/8.5/en.php");
var_dump($components['host']);
// string(7) "php.net"
use Uri\Rfc3986\Uri;
$uri = new Uri("https://php.net/releases/8.5/en.php");
var_dump($uri->getHost());
// string(7) "php.net"
Modify properties while cloning readonly objects
final readonly class PhpVersion {
public function __construct(
public string $version = 'PHP 8.4',
) {}
public function withVersion(string $version) {
$newObject = clone $this;
$newObject->version = $version;
return $newObject;
}
}
var_dump(new PhpVersion()->withVersion('PHP 8.5'));
// 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) {
return clone($this, ['version' => $version]);
}
}
$version = new PhpVersion();
var_dump(
$version->withVersion('PHP 8.5'),
$version->version,
);
Transform nested function calls into readable pipelines
$input = ' Some kind of string. ';
$output = strtolower(
str_replace(['.', '/', '…'], '',
str_replace(' ', '-',
trim($input)
)
)
);
$input = ' Some kind of string. ';
$output = $input
|> trim(...)
|> (fn (string $string) => str_replace(' ', '-', $string))
|> (fn (string $string) => str_replace(['.', '/', '…'], '', $string))
|> strtolower(...);
Convenient array boundary access functions
$php = [
'php-82' => ['state' => 'security', 'branch' => 'PHP-8.2'],
'php-83' => ['state' => 'active', 'branch' => 'PHP-8.3'],
'php-84' => ['state' => 'active', 'branch' => 'PHP-8.4'],
'php-85' => ['state' => 'upcoming', 'branch' => 'PHP-8.5'],
];
$upcomingRelease = null;
foreach ($php as $key => $version) {
if ($version['state'] === 'upcoming') {
$upcomingRelease = $version;
break;
}
}
var_dump($upcomingRelease);
$php = [
'php-82' => ['state' => 'security', 'branch' => 'PHP-8.2'],
'php-83' => ['state' => 'active', 'branch' => 'PHP-8.3'],
'php-84' => ['state' => 'active', 'branch' => 'PHP-8.4'],
'php-85' => ['state' => 'upcoming', 'branch' => 'PHP-8.5'],
];
$upcomingRelease = array_first(
array_filter(
$php,
static fn($version) => $version['state'] === 'upcoming'
)
);
var_dump($upcomingRelease);
Warn when function return values are ignored
function getPhpVersion(): string {
return 'PHP 8.4';
}
getPhpVersion(); // No Errors
#[\NoDiscard]
function getPhpVersion(): string {
return 'PHP 8.4';
}
getPhpVersion();
// Warning: The return value of function
// getPhpVersion() should either be used or
// intentionally ignored by casting it as (void)
Use closures and callables in attributes
final class CalculatorTest extends \PHPUnit\Framework\TestCase
{
#[DataProvider('subtractionProvider')]
public function testSubtraction(
int $minuend,
int $subtrahend,
int $result
): void
{
$this->assertSame(
$result,
Calculator::subtract($minuend, $subtrahend)
);
}
public static function subtractionProvider(): iterable
{
for ($i = -10; $i <= 10; $i++) {
yield [$i, $i, 0];
yield [$i, 0, $i];
yield [0, $i, -$i];
}
}
}
final class CalculatorTest
{
#[Test\CaseGenerator(static function (): iterable {
for ($i = -10; $i <= 10; $i++) {
yield [$i, $i, 0];
yield [$i, 0, $i];
yield [0, $i, ($i * -1)];
}
})]
public function testSubtraction(
int $minuend,
int $subtrahend,
int $result
)
{
\assert(
Calculator::subtract($minuend, $subtrahend) === $result
);
}
}
Simplified and improved cURL connection pooling
$sh = curl_share_init();
curl_share_setopt($sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
curl_share_setopt($sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
$ch1 = curl_init('https://php.net/');
curl_setopt($ch1, CURLOPT_SHARE, $sh);
curl_exec($ch1);
$ch2 = curl_init('https://thephp.foundation/');
curl_setopt($ch2, CURLOPT_SHARE, $sh);
curl_exec($ch2);
curl_share_close($sh);
curl_close($ch1);
curl_close($ch2);
$sh = curl_share_init_persistent([
CURL_LOCK_DATA_DNS,
CURL_LOCK_DATA_CONNECT
]);
$ch1 = curl_init('https://php.net/');
curl_setopt($ch1, CURLOPT_SHARE, $sh);
curl_exec($ch1);
$ch2 = curl_init('https://thephp.foundation/');
curl_setopt($ch2, CURLOPT_SHARE, $sh);
curl_exec($ch2);
curl_close($ch1);
curl_close($ch2);
Constructor property promotion now available for final properties, reducing boilerplate code.
Apply attributes to class constants for better metadata support and documentation.
The Override attribute now works on properties, catching inheritance errors at compile time.
Mark traits as deprecated to guide developers away from legacy code patterns.
Define different read/write visibility levels for static properties.
New attribute for deferring target validation in attribute processing.
Access error and exception handlers with get_error_handler() and get_exception_handler().
New getElementsByClassName() and insertAdjacentHTML() methods for DOM manipulation.
New enchant_dict_remove_from_session() and enchant_dict_remove() for spell checking.
Calculate Levenshtein distance for Unicode grapheme clusters.
New opcache_is_script_cached_in_file_cache() function for cache validation.
New ReflectionConstant and ReflectionProperty methods for deeper code introspection.
PHP 8.5 maintains strong backward compatibility with minimal breaking changes.
PHP 8.5 focuses on adding new features while maintaining compatibility. No major deprecations in this release. Check the migration guide for detailed information.
Long-term support commitment for enterprise-grade stability and security.
PHP 8.5.0 released to production with full feature set, comprehensive documentation, and migration guides.
Transition to security-only updates. Bug fixes and general maintenance conclude after two years.
Security support concludes. Migration to PHP 8.6+ strongly recommended for continued protection.
Download PHP 8.5 and experience the next generation of web development.