Blog / Discover what's new in PHP 8.5!

Discover what's new in PHP 8.5!

by SW Team

PHP 8.5 is here

PHP launches the new version 8.5, reinforcing its commitment to readability, security, performance, and modernisation of the language.

At SW Hosting, we focus on always offering you the cutting-edge technology you need to maximise the efficiency and performance of your developments. PHP 8.5 is now available free of charge for hosting plans, as well as being included in our cloud services with SWPanel on Debian 11 and 12, both in the cloud and self-hosted versions.

Below, we outline the most notable new features and why you should update as soon as possible

Your Cloud with Debian 13 from $8.51/month

Start your project with the stability of Debian 13 in a fully scalable and customisable Cloud.

Why upgrade to PHP 8.5 now?

  • Cleaner, more modern code: thanks to improvements such as the pipe operator, clone-with, closures in constants, new array helpers, etc.

  • Better performance and efficiency: although there is no revolution in JIT, internal optimisations, less boilerplate and new utilities help to write more maintainable and potentially faster code.

  • More robust debugging: better errors, fatal back-traces, handler inspection functions, making it easier to find and fix bugs.

  • Ready for the future and standards: with native URI, better internationalisation support, and deprecations that push for cleaner code.

What services include PHP 8.5?

  • Shared hosting: al

  • Cloud with SWPanel: all those installed on Debian 11 or higher. Whether self-hosted or on the SW Hosting infrastructure.

Do I need to request it in any way?

You don't need to do anything. It's already installed.

How to start using PHP 8.5 in your projects

  • Check the compatibility of your dependencies/composers.

  • Run your tests (unit/functional).

  • Check warning logs to detect uses of deprecated features.

  • Take advantage of the new functions and features little by little in new parts of the code.

Your Quality Hosting from $3.74/month

Our Hosting gives you the freedom to tailor your website to your brand and goals.

Main new features in PHP 8.5

Native URI extension

PHP 8.5 includes a standard extension for working with URIs/URLs in accordance with the RFC 3986 and WHATWG standards. This allows URLs to be analysed, normalised and manipulated natively, securely and more reliably.

Basic example:

use Uri\\Rfc3986\\Uri;

$uri = new Uri('https://ejemplo.com/ruta?param=1');
echo $uri->getHost(); // "ejemplo.com"

Pipe operator (|>)

One of the most eagerly awaited new features: the |> operator allows function calls to be chained from left to right, improving readability and reducing the need for intermediate variables.

Comparative example:

// Previously (nested)
$result = trim(strtoupper(str_shuffle($string)));

// With pipe
$result = $string
    |> strtoupper(...)
    |> str_shuffle(...)
    |> trim(...);

Clone with modifiable properties (“Clone With”)

You can now clone objects and modify their properties in a single expression — ideal for readonly classes and for applying the “with-er” pattern cleanly.

$new = clone($oldObject, ['propiedad' => $nuevoValor]);

Attribute #[\\\\NoDiscard]

With this new attribute, you can mark functions or methods whose return value should not be ignored. PHP will issue a warning if the return value is not used. Very useful for critical APIs or functions where the return value matters.

First-class closures and callables in constant expressions

It is now possible to use static closures or callables as constant values, for example in attribute parameters, default properties, constants, etc. This opens up more dynamic possibilities within static definitions.

New functions and utility improvements

PHP 8.5 brings several new functions and minor improvements designed to make everyday development easier:

  • array_first() y array_last() — to directly obtain the first or last element of an array.

  • New functions for handling errors: get_error_handler(), get_exception_handler() and improvements to back-traces when a fatal error occurs.

  • New compilation constants (PHP_BUILD_DATE, …).

  • Improvements in internationalisation: for example, support for detecting whether a locale is written from right to left (locale_is_right_to_left() / Locale::isRightToLeft).

  • Other specific improvements in extensions such as cURL, DOM handling, partitioned cookies, asymmetric visibility in static properties, support for final in properties through “constructor property promotion”, etc.

Deprecations and compatibility changes

Upgrading to PHP 8.5 not only adds new features, it also removes or marks certain old elements as obsolete. Among them:

  • The backtick operator (alias for shell_exec()) is now deprecated.

  • Scalar type casts with non-canonical names: (boolean), (integer), (double), (binary) are deprecated. Now (bool), (int), (float), (string).

  • Some old syntax constructs have been discouraged or cause warnings: for example, destructuring non-array values, using null as an array offset or in array_key_exists(), case endings with semicolons instead of colons, class aliases such as class_alias("array",…), etc.

  • The magic methods __sleep() y __wakeup() have been “soft-deprecated”: it is recommended to use __serialize() y __unserialize() en su lugar.

As always, it is advisable to review your code base before updating to avoid any surprises.

Conclusion

PHP 8.5 does not represent a radical change, but it does include many improvements designed to modernise the language, making it more secure, readable, and efficient. If you want to keep your code up to date and take advantage of new development and maintenance features, it is well worth migrating.

i
Email send icon