Software Engineering UKSoftware Engineering UK
PHP 8.6: A Quick Guide to the Best Upgrades
Software Engineering UK

PHP 8.6: A Quick Guide to the Best Upgrades

Kelly MatthewsWords by Kelly Matthews

Further up the stream

Tideways ran Symfony, Laravel and WordPress through one load harness on PHP 8.4, 8.5 and 8.6 and found the differences small enough that a live application would never register them, as its benchmark write-up records. That finding should shape the plan before anyone edits a composer.json. A slow service does not become fast because the version string changed, and a team that sells the upgrade internally as a performance win will spend the next quarter explaining why the dashboards stayed flat.

The release pays out in narrower, more durable ways: syntax that deletes boilerplate, a runtime that fails loudly where it used to warn, and defaults that close doors nobody meant to leave open. PHP 8.6.0 shipped on 19 November 2026, and the official release announcement sums it up as "Faster, Safer, More Powerful". The middle word changes production behaviour, so the work divides into what deserves a refactor slot and what needs checking before the build goes out.

The language changes worth a refactor slot

Partial function application shows up first in most code reviews. Put a question mark where an argument belongs and PHP hands back a Closure that waits for the rest, which turns a call into a callable without an arrow function wrapped around it.

// Before: a closure that exists only to carry one argument
$supportsPfa = array_filter(
    $versions,
    fn (string $version): bool => version_compare($version, '8.6', '>='),
);

// PHP 8.6: the same call with that argument left open
$supportsPfa = array_filter($versions, version_compare(?, '8.6', '>='));

Two details decide whether the feature cleans a codebase or quietly changes it. Arguments you supply are evaluated at the moment the partial is created, and Moneo's release write-up flags that timing as the trap for anything with side effects, such as a generated request ID. The Dev Dispatch release guide adds that a follow-up RFC made every question mark a required parameter, so the arity you write is the arity the caller must satisfy and the placeholder leaves optional arguments untouched. Moneo also notes that new cannot be partially applied, while a static factory method can.

Duration earns its place for a different reason. Timeouts, back-off and benchmark timings have been passed around as integers in an unknown unit or as floats that drift; the new class makes the unit explicit, keeps nanosecond precision, and offers factories for the smaller units and for ISO 8601 strings.

use Time\Duration;

function backoff(Duration $baseDelay, Duration $step, int $attempt): void
{
    $delay = $baseDelay->add($step->multiplyBy(2 ** $attempt));
    $delay = min($delay, Duration::fromSeconds(30));
    time_nanosleep($delay->seconds, $delay->nanoseconds);
}

Because durations are comparable, min() accepts them directly, and the release announcement positions the class for timeouts and benchmark timings where a calendar unit would be wrong. The polling API already takes it as a timeout type, which is the strongest hint that internal APIs will follow.

clamp() does one job and validates while doing it. The max($min, min($max, $value)) idiom silently accepts swapped bounds and lets NAN through; the built-in throws a ValueError when the minimum exceeds the maximum or either bound is NAN, and it compares strings, DateTimeImmutable objects and durations using PHP's ordinary comparison rules. The SortDirection enum with its Ascending and Descending cases is the same kind of fix aimed at library authors: TecAdmin's release write-up notes that no built-in function accepts it yet, so the immediate value sits in your own public APIs, where a typed direction beats an integer flag or a string literal.

Readonly property defaults look small and behave strictly. The default counts as the property's single initialisation, so a constructor that also assigns it throws, and unset() on such a property is an error, as the Dev Dispatch guide sets out. That makes the feature a target for a search-and-destroy pass before you lean on it: any readonly class that gains a default and keeps its constructor assignment will fail the first time a test constructs it. The same pass is a good moment to replace isPublic() checks in serialisers and hydrators with ReflectionProperty::isReadable() and isWritable(), which understand readonly, asymmetric visibility and hooks. Doc comments move closer to the code too: a comment written above a parameter is returned by ReflectionParameter::getDocComment(), which gives attribute-driven frameworks and API generators the text straight from reflection. Add #[\Override] on class constants and enum cases to the same sweep, since the compiler will then fail a rename of the parent constant, where an unmarked override would quietly define a new one with the same name.

At the runtime layer, Io\Poll gives event loops a native multiplexing backend chosen per platform, and the improvement reaches your application through ReactPHP, AMPHP or Revolt. Only stream resources are pollable in this first version. Structured stream errors are the more immediately useful piece: a stream context can be told to throw a StreamException or to collect errors silently, and the resulting StreamError objects carry a code enum, the wrapper name and the affected path. That is a long way from parsing warning text out of a custom error handler.

The smaller additions repay a scan of your dependency list. The Sodium extension gains post-quantum key encapsulation with X-Wing and ML-KEM-768, TLS streams gain session resumption, external pre-shared keys and TLS 1.3 early data, and the new URI builders assemble a URI in one object with type detection for URLs and hosts. JSON error messages now report where in the input the fault sits, the new error_include_args INI setting puts function arguments into error messages, grapheme_strrev() reverses a string by grapheme cluster, and ZipArchive::openString() works on an archive held in memory.

The migration checklist that keeps production running

Start with the calendar, because it decides how much room the team has.

Branch Active support ends Security-only support ends Position for a team still on it
8.2 31 December 2024 31 December 2026 Move before the year is out; the branch stops receiving fixes
8.3 31 December 2025 31 December 2027 No bug fixes arriving; queue the move
8.4 31 December 2026 31 December 2028 Supported, and this is the window to plan 8.6
8.5 31 December 2027 31 December 2029 Test 8.6 here first, then cut over
8.6 31 December 2028 31 December 2030 Target for new work once dependencies confirm

Dates come from the TecAdmin release write-up, which applies PHP's two years of active support followed by two years of security fixes; the 8.6 row follows that policy and had not yet been published on the supported versions page at release.

Sessions are the change most likely to break something you cannot reproduce locally. The defaults moved.

INI setting PHP 8.5 default PHP 8.6 default What stops working
session.use_strict_mode 0 1 Session IDs PHP never issued are rejected, so any flow that mints its own IDs breaks
session.cookie_httponly 0 1 JavaScript can no longer read the session cookie
session.cookie_samesite unset Lax Cross-site POST callbacks lose the cookie unless you set None together with Secure

The values are documented in the php-src UPGRADING file for the PHP-8.6 branch, which also records the consequences. Payment and single sign-on callbacks that post across sites need SameSite=None plus a secure cookie; front-end code that reads the session cookie needs the setting restored deliberately. Custom session handlers must now implement both create_sid and validateId or they are deprecated, and a handler that relied on write() being called with empty data should move that logic into updateTimestamp().

Then sweep the deprecations with the test suite, with E_ALL and E_DEPRECATED switched on in CI and notices treated as failures for one cycle. The ones that bite are usually the mbstring regex functions, which lose their Oniguruma backing library, the is_double, is_long, is_integer and doubleval aliases, spl_object_hash in favour of spl_object_id, strcoll and the SORT_LOCALE_STRING flag in favour of Collator, a return inside a finally block, and values returned from __construct or __destruct. Objects passed where an array is expected by array_walk, http_build_query, mb_convert_variables and the compression functions now raise a deprecation, so convert with get_object_vars first. Bug Circuit's upgrade guide makes the same point from the site owner's side: a plugin or theme that has not been updated in years is the usual source of trouble, and the deprecation notices in the log are the early warning.

Behaviour changes deserve their own test pass, because they fail without a deprecation notice. trim, ltrim and rtrim now strip the form feed character by default, which changes any byte-level comparison against trimmed input. fclose, file_put_contents and copy now return false when the flush or close fails, so code that ignored the return value starts seeing silent failures. Many functions now throw a ValueError for out-of-range values, invalid flags and strings containing NUL bytes where they used to truncate or ignore the input. The php-src upgrade notes list these under backward-incompatible changes and reward a careful read before the release branch reaches a shared host.

The order of operations matters as much as the list. Bug Circuit's staged sequence is worth adopting wholesale: record the current version, take a backup and build a staging copy, move staging to 8.5 first, read the error log with display_errors off and log_errors on, check the extension list with php -m, run composer check-platform-reqs on the staging server while it runs the target version, update plugins and packages, then repeat the same tests on 8.6. Fixing issues in two small steps beats one big jump, and the same sequence works for a framework application without the WordPress vocabulary.

Production cutover gets a quiet hour, the backup left in place and a named person watching the error log and the key pages. A rollback to the previous version in the host panel is the fallback and belongs in the change ticket before anyone runs it. Then wait for the dependency graph to confirm 8.6 support before code that uses the new syntax lands, since a library declaring a platform constraint of 8.5 will block the composer update however clean your own source looks.

Sources

Source: PHP 8.6 is a major update of the PHP language

The usual questions

What is partial function application in PHP 8.6?

It allows a developer to leave an argument open using a question mark. PHP then returns a Closure that waits for the remaining arguments.

How does the new clamp() function work?

It restricts a value between a minimum and maximum bound. It throws a ValueError if bounds are swapped or if either bound is NAN.

What is the purpose of the Duration class?

It provides an explicit way to handle timeouts and benchmarks with nanosecond precision. It replaces the use of floats or integers.

What happens with readonly property defaults?

A default value counts as the property's single initialisation. Attempting to assign a value in the constructor will cause the code to throw.

Filed so far