PHP 8.6 is here and ready to use on 20i

PHP 8.6 is available on 20i hosting. You can switch your sites over today from My20i, in just a few clicks.

This is a big release. It brings cleaner syntax, stronger types and better tools for high-traffic apps. Here’s what’s new, what’s changed and what to check before you upgrade.

The headline features

Partial Function Application

You can now fill in some of a function’s arguments up front and get back a Closure that takes the rest. Use ? for a single missing argument and ... for the remainder. It means fewer throwaway arrow functions in your code.

// PHP 8.5
$supported = array_filter($versions, fn ($v) => version_compare($v, '8.6', '>='));

// PHP 8.6
$supported = array_filter($versions, version_compare(?, '8.6', '>='));

A new Duration class

\Time\Duration represents elapsed time, like a stopwatch reading. It has nanosecond precision, covers more than 250 years and doesn’t care about timezones. That makes timeouts, retries and benchmarks far easier to read than raw microsecond integers.

use Time\Duration;

$timeout = Duration::fromSeconds(30);
$retryAfter = Duration::fromMilliseconds(250);

The Polling API

The new Io\Poll API watches lots of streams at once using the best method each platform offers (epoll, kqueue, event ports or WSAPoll). It removes the 1,024 connection ceiling that often limits stream_select(). Event loop libraries such as ReactPHP and AMPHP can now build on one shared, native foundation.

clamp()

A small one that you’ll use all the time. clamp() keeps a value inside a range and returns the nearest boundary if it falls outside.

clamp(110, 0, 100); // 100
clamp(-10, 0, 100); // 0

It works with any comparable value, including the new Duration class.

SortDirection enum

SortDirection::Ascending and SortDirection::Descending give every library one standard, type-safe way to express sort order. No more mixing integers, strings and booleans across packages. Pass the wrong thing and you get a clear TypeError rather than a confusing failure deep inside a method.

Readonly property defaults

Readonly properties can now declare a default value directly. Fixed values no longer need assigning in the constructor, so classes get shorter and easier to scan.

Structured stream errors

Stream operations can now throw a StreamException or fail quietly instead of emitting warnings. Each error comes with a StreamErrorCode enum, the wrapper name and the affected path or URL. That’s a big step up from parsing the message string out of error_get_last().

Better tools for developers

  • Function and method parameters can have their own DocComments, readable through ReflectionParameter::getDocComment()
  • New ReflectionProperty::isReadable() and isWritable() methods tell you whether a property can actually be read or written, taking readonly, asymmetric visibility and hooks into account

Performance improvements

PHP 8.6 includes several under-the-hood speed-ups:

  • array_map() calls using first-class callables or partial application now compile into plain loops
  • Faster printf() calls and faster JSON encoding
  • Stateless closures are cached

Other improvements worth knowing

  • Security: the Sodium extension adds post-quantum key encapsulation (X-Wing and ML-KEM-768), IP address encryption and SHAKE/TurboSHAKE functions
  • TLS: streams now support session resumption, external pre-shared keys and TLS 1.3 early data (0-RTT)
  • URIs: new builder classes for RFC 3986 URIs and WHATWG URLs, plus host and URI type detection
  • MySQL: a new mysqli::quote_string() method escapes and quotes a string, matching PDO::quote()
  • Debugging: JSON error messages now point to where the error is in the input
  • Archives: ZipArchive::openString() and closeString() work with zip files held in memory
  • Enums and attributes: #[\Override] now works on class constants and enum cases, and enums can implement __debugInfo()

Check these before you upgrade

Most of the changes below are deprecations. Your code will still run, but you’ll see notices and these features will be removed in a future version. A few are genuine behaviour changes, so they’re worth a look.

Deprecations to look out for:

  • return inside a finally block, because it silently swallows exceptions
  • Returning a value from __construct() or __destruct()
  • The mbstring regex functions such as mb_ereg() and mb_split() (use PCRE with the u modifier instead)
  • The aliases is_double(), is_long(), is_integer() and doubleval() (use is_float(), is_int() and floatval())
  • spl_object_hash() in favour of spl_object_id()
  • strcoll() and SORT_LOCALE_STRING (use the intl Collator class)
  • Passing an object where an array is expected to array_walk(), http_build_query() and similar functions
  • Using let or is as a class, function or constant name

Behaviour changes:

  • Sessions are more secure by default: session.use_strict_mode and session.cookie_httponly are on, and session.cookie_samesite is set to Lax
  • Custom session handlers that don’t implement both create_sid() and validateId() are deprecated
  • fclose(), file_put_contents() and copy() now return false if flushing or closing fails
  • Many functions now throw a ValueError for out-of-range values, invalid flags or strings with NUL bytes
  • trim(), ltrim() and rtrim() now strip form feed characters by default

If you run WordPress or another CMS, check that your theme and plugins support PHP 8.6 before switching your live site. The official migration guide has the full list.

How to switch to PHP 8.6 on 20i

  1. Log in to My20i and go straight to the PHP Version Manager
  2. Select the sites you want to update
  3. Choose PHP 8.6 and save

The change takes effect straight away. If anything doesn’t look right, you can switch back to your previous version from the same screen.

Top tip: test first on a staging site or a copy of your site, especially if you’re jumping up from PHP 8.4 or earlier.

Ready when you are

PHP 8.6 is faster, safer and more expressive, and it’s ready to use across 20i hosting right now. Not hosting with us yet? Explore 20i hosting and get the latest PHP from day one.

If you need a hand upgrading, our support team is available 24/7.

Previous Article

Win back lost sales with abandoned basket reminders in HostShop

Next Article

The Rise of .si and .app Domain Names

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *