Send files quickly, easily and securely with File Express. Free and brand new! Discover now
PHP 8.5: the key features at a glance

PHP 8.5: the key features at a glance

The newly released version 8.5 of PHP is now also available on Hostpoint via the settings in the Control Panel. This allows you to easily install the updated version yourself. In this blog post, we take a look at the most important new features and what they mean for your applications.

Vincent Jancso Vincent Jancso · System Engineer

New array helpers, the new pipe operator, improvements to object cloning and more modern URL parsing and error handling: with PHP 8.5, developers of the popular scripting language for web applications are continuing to bring out new features without creating unnecessary obstacles for existing projects. Rather than delivering major updates, the new version provides a whole range of thoughtful small improvements that make a big difference when implemented together.

For Hostpoint customers, this means that you can easily test PHP 8.5 via the Hostpoint Control Panel and implement it gradually. Instructions can be found in our Support Center.

Find relevant values faster with array helper functions

PHP 8.5 introduces two handy functions, array_first() and array_last(), which directly return the first and last value of an array. If the array is empty, both functions return zero. They supplement the existing functions array_key_first() and array_key_last(), which only return the keys.

Until now, developers often needed to use separate helper functions or a combination of different array operations in order to solve this task, creating small helper functions in many projects, and often several times in different places. Although this process works, it results in repeated patterns and inconsistent handling of empty arrays.

As shown above, when evaluating a chronologically sorted list of results or looking at measured values, without any additional logic, you will arrive at the oldest or most recent entry.

With array_first() and array_last(), the intent becomes immediately clear. This keeps the code concise and easy to read.

The pipe operator |> – more readable processing chains

The pipe operator |> allows you to move a value step by step through several functions. The result on the left is passed as an argument to the function on the right.

With the pipe operator, first-class callable syntax such as trim(…) or strtolower(…) must be used so that the expression can be passed as callable. This syntax has existed since PHP 8.1 and has the advantage that typos can already be detected during static code analysis in the code editor.

Without a pipe operator, processing chains were built either using nested function calls or using multiple intermediate variables. Both are technically correct, but quickly become confusing if several steps are required in sequence, such as when transforming strings or filtering and sorting arrays.

With |>, the data flow can be read from left to right. A value can be trimmed, converted to lowercase letters, filtered and then further processed without the code appearing nested.

You benefit most from the pipe operator when several functions are executed in sequence with one specific relevant input value.

Compared to traditional variants with nested function calls or several intermediate variables, pipe operator chains can in some cases be more resource-efficient and perform better. Often, there’s no need for custom collection helper classes, which would only wrap array_map() or array_filter() internally anyway.

For more complex signatures, small anonymous functions are still useful. The operator supplements existing structures instead of replacing them completely.

Object clones with changed properties

PHP 8.5 extends the behavior of clone(). When cloning an object, specific properties can be modified by passing an additional associative array with new property values to clone. This is particularly well suited to immutable classes, where variants of an object are intended to be created without modifying the original.

Until now, custom with methods were implemented for such cases, which read the current object state, selectively modify it and write it into a new instance. For classes with many properties, this results in extensive boilerplate code, which has to be updated every time the class is extended.

With the new clone() variant, object variants can be formulated much more concisely. The intent is immediately clear: a copy is created where only individual values differ. This is useful, for example, in domain models, configuration objects or value objects that are intended to remain immutable.

Safe and modern URL processing

The parse_url() function does not follow any official standard and behaves inconsistently, especially in edge cases. In addition, the official documentation explicitly states that parse_url() is not intended for untrusted or intentionally manipulated input. This is why, in many projects, custom helper functions or external libraries had to be used in order to parse, normalize and process URLs reliably and securely.

The newly released version 8.5 of PHP introduces a new URI extension that parses and processes URLs according to current standards. Instead of arrays, specialized objects are used that clearly separate components such as scheme, host, path or query parameters. This reduces the need for project-specific helper functions and makes the behavior more predictable, such as when setting up redirects or saving external links.

Other small improvements at a glance

In addition to the major changes mentioned above, this version of PHP brings a number of other small improvements, which are particularly noticeable in the operation of larger or specialized applications. OPcache is now part of the PHP installation and is loaded by default.

Alongside this, there have been improvements to diagnostics: functions such as get_error_handler() and get_exception_handler() provide insight into active error handling, and the CLI flag php –ini=diff displays only configuration values that differ from the default values.

Deprecations – what to consider

Like every new version, PHP 8.5 marks certain patterns as deprecated without removing them immediately. These deprecations initially generate warnings and prepare for future changes.

In many code bases, there are still spellings like (integer), (boolean) and (double) instead of int, bool and float. Backticks as an alias for shell_exec() or older serialization patterns using __sleep() and __wakeup() are still around. PHP 8.5 also marks several “close” functions such as curl_close(), curl_share_close(), finfo_close() or xml_parser_free() as deprecated; since the migration of these extensions from resources to objects, they no longer have any effect and the associated objects are automatically released.

By activating warning output and inspecting the logs in a test or staging environment, issues can be addressed selectively. In the medium term, this reduces the effort required for future version upgrades, keeps error logs concise and at the same time ensures that the code stays closer to the recommendations of the current PHP generation.

Our migration tips

To ensure a controlled transition to PHP 8.5, a structured approach recommended by Hostpoint has proven effective.

  1. Check the project and its dependencies
    First, get an overview: which frameworks, libraries and extensions are you using, and from which versions is PHP 8.5 officially supported? The release notes of the respective projects help to identify common pitfalls early on.

  2. Set up a staging environment with PHP 8.5
    Set up a test or staging instance that closely resembles your production environment. In the Hostpoint Control Panel, you can activate PHP 8.5 for this environment while the live website continues to run on the current version.

  3. Test the application and monitor the logs
    Run existing automated tests under PHP 8.5 and manually check key functions – such as login areas, ordering or contact processes, and integrations with third-party systems. Activate the output of errors and deprecation notices and check the log files regularly.

  4. Modify code and make targeted use of new features
    Fix reported errors and deprecations step by step. Once the application is stable, you can modernize the parts of the code where new features – such as array_first(), array_last(), the pipe operator, clone() with property updates or the URI extension – clearly simplify the code.

  5. Plan the migration and use Hostpoint options
    Schedule the final migration to PHP 8.5 for a quiet period and keep an eye on the log files after the migration. If any unexpected issues arise, you can switch back to the previous PHP version at any time in the Hostpoint Control Panel and analyze the cause at your own pace.

With good preparation, the migration to PHP 8.5 can run smoothly and efficiently without compromising system stability. If you have any questions about the migration, our Support Center and our support team will be happy to help you.

Bottom line

Rather than being a mandatory update, the new version is more of a well-calculated step forward. By cleaning up deprecations and using selected new features such as array helpers, pipe operators or URI extensions, you can reduce technical debt and prepare for future PHP versions. Thanks to Hostpoint’s flexible PHP version selection, you can plan the migration at your own pace, first test it in a staging environment and then roll it out step by step.

Newsletter

Do you know the Hostpoint newsletter?

Relevant news about products and new features, current blog articles, and open jobs!

Send and receive files with File Express

The most modern, secure and simple way to send files. With free file transfers of up to 50 GB. And all data stored exclusively in Switzerland.

Cookie Cookie

We use Cookies 🍪

Hostpoint's digital presences (website, Control Panel, Support Center, etc.) use cookies. These are used to collect data on visitor interactions. If you click “Accept”, you agree to the use of these cookies for advertising purposes, website analysis and support. However, certain cookies are essential for the proper functioning of these pages and therefore cannot be disabled. Even without your consent, certain data may be used in anonymized form for statistical purposes and to improve our websites. Please note our Privacy policy.

Decline
Accept