PHP 8.5 now officially released

Ingmar Aasoja
RSS: Share:

At the end of November, PHP version 8.5 was officially released. Zone servers have offered early access for several months already, starting from the beta phase. Each new version deprecates outdated features and introduces fresh improvements. In this article, we focus on the most notable new capabilities.

PHP 8.5 now officially released

The Pipe Operator (|>)

This is arguably one of the coolest syntax updates in years – something PHP developers could hardly have imagined not too long ago. It significantly improves code readability and makes everyday development more fluent.

The pipe operator is especially useful when working with arrays and strings. If achieving the final result requires passing a variable through several functions, you can now chain them together more elegantly.

Example of removing odd numbers from a sequence:

PHP 8.4

$numbers = implode(',', 
    array_filter(
        explode(',', '1,2,3,4,5,,6'), 
            function ($var) { 
                  return $var && !($var & 1); 
            }
      )
);

echo $numbers; // 2,4,6
Code language: PHP (php)

PHP 8.5

$numbers = '1,2,3,4,5,,6'
    |> (fn($s) => explode(',', $s))
    |> (fn($xs) => array_filter($xs, fn($var) => $var && !($var & 1)))
    |> (fn($xs) => implode(',', $xs));

echo $numbers; // 2,4,6
Code language: PHP (php)

array_first and array_last Functions

As the names suggest, these new functions return the first and last values of an array. Earlier, array_key_first and array_key_last helped somewhat, but developers still needed to manually check whether the elements existed at all.

PHP 8.4

$names = ['john', 'smith'];
$lastName = $names === [] ? null : $names[array_key_last($names)];

echo $lastName; // smithCode language: PHP (php)

PHP 8.5

$names = ['john', 'smith'];
$lastName = array_last($names);

echo $lastName; // smithCode language: PHP (php)

Stack Trace in Fatal Error Messages

When a program crashed due to a fatal error, it was often difficult to pinpoint where the underlying issue actually occurred. PHP 8.5 now provides a more informative stack trace in fatal error messages. Note: this requires enabling fatal_error_backtraces = On in your php.ini configuration.

ini_set('memory_limit', '2M');

$dates = [];

function collectDates($dates) { 
    while (true) {
        $dates[] = time();
    }
}

collectDates($dates);Code language: PHP (php)

PHP 8.4 output:

Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 2097160 bytes) in /test.php on line 9

PHP 8.5 output:

Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 2097160 bytes) in /test.php on line 9
Stack trace:
#0 /test.php(13): collectDates(Array)
#1 {main}Code language: PHP (php)

URI Extension

Previously, extracting information from a URL required parsing it manually and checking whether the needed part was present. PHP 8.5 introduces a dedicated extension that simplifies this process:

PHP 8.4

$parsed = parse_url('https://example.com:80');

echo $parsed['port'] // 80
echo $parsed['path'] // Warning: Undefined array key "path" ...Code language: PHP (php)

PHP 8.5

use Uri\Rfc3986\Uri;

$uri = new Uri('https://example.com:80');

echo $uri->getPort(); // 80
echo $uri->getpath(); // ""
echo $uri->withPort(null)->toString(); // https://example.comCode language: PHP (php)

#[\NoDiscard] Attribute

When a function’s return value matters, developers can now enforce its usage by adding the #[\NoDiscard] attribute. This helps catch situations where an important return value might otherwise be ignored.

PHP 8.4

function getName() {
    return 'Sohn Smith';
}

getName();Code language: PHP (php)

PHP 8.5

#[\NoDiscard] 
function getName() {
    return 'Sohn Smith';
}

getName();

// Warning: The return value of function getName() should either be used or intentionally ignored by casting...Code language: PHP (php)

Kokkuvõtteks

Summary

More detailed information about this release is available on the official PHP website, which now includes a dedicated page for PHP 8.5. It’s also worth noting that security updates for PHP 8.1 will end in late 2025, and PHP 8.3 is transitioning from active support to security-only updates. We strongly recommend updating existing applications to the newest version as soon as possible. Laravel 12 and the newly released Symfony 8.0 already offer full support for PHP 8.5.

Popular posts

.NO domain now at Zone – is your business ready for the Norwegian market?

.NO domain now at Zone – is your business ready for the Norwegian market?

Ants Korsar
If you are planning to expand into Norway, or are already doing business there, now is the right time to secure a local and trustworthy web address. The...
Zone Webmail 3.0: New features that make email management easier than ever

Zone Webmail 3.0: New features that make email management easier than ever

Nikita Tikhomirov
The upgraded version of Zone Webmail is here, offering a fresh and user-friendly experience. Our goal with this new update was simple: every feature should...
Still the rightful owner of your domain? ICANN’s new rule means it’s time to double-check

Still the rightful owner of your domain? ICANN’s new rule means it’s time to double-check

Jaanus Putting
Starting 28 May 2025, a new policy by ICANN comes into effect, and it impacts all owners of generic domains like .COM, .ORG, and .NET. Sounds technical?...
Why choose a .EU domain today?

Why choose a .EU domain today?

Jaanus Putting
We live in a time where global power dynamics are shifting faster than ever before. While Europe is moving towards a stronger, more unified internal market,...