PHP 8.6: what changes in code you already have
PHP 8.6.0 was released on 19 November 2026. The release page leads with partial function application, a clamp() function, a SortDirection enum, readonly property defaults, a Time\Duration class and a polling API. Most of those are for ordinary application code, not just library authors. One of them can break a codebase that has never heard of PHP 8.6, and a second changes session cookies without a line of your code changing.
The short version, before the detail:
- If any
helpers.phpin your project or your dependencies defines a globalclamp(), check it before upgrading. Defined unconditionally, it is a fatal error. Wrapped infunction_exists(), it is skipped and PHP’s own version, which may take its arguments in a different order, runs instead. session.use_strict_mode,session.cookie_httponlyandsession.cookie_samesitenow default to1,1andLax. If nophp.inisets them, your session cookies change on upgrade.- Partial application (
f(?, 'x')) replaces most of the one-linefn ($x) => ...closures you pass toarray_filterandarray_map.
Everything below was run on the official php:8.6-cli Docker image (PHP 8.6.0), with php:8.5-cli (PHP 8.5.13) for comparison, on 20 November 2026. The polling API was only checked to exist, not exercised.
The clamp() collision
clamp() is an obvious name for a three-line helper, and PHP never had one, so a global function by that name in a helpers.php somewhere is a real possibility. If yours declares it without a guard, 8.6 refuses to load the file:
Fatal error: Cannot redeclare function clamp() in /work/redeclare.php on line 2
That one at least fails on the first request. The guarded version is quieter. The if (! function_exists(...)) guard is the usual way to ship global helpers without clashing. On 8.6 the guard sees the built-in, skips your definition, and every call goes to PHP’s clamp(mixed $value, mixed $min, mixed $max) instead.
If your helper used the same order, nothing changes. If it took ($min, $max, $value), this is what happened in the test:
if (! function_exists('clamp')) {
function clamp($min, $max, $value) {
return max($min, min($max, $value));
}
}
clamp(0, 100, 150);
clamp(0, 10, 5);
8.5.13: int(100) int(5)
8.6.0: int(100) ValueError: clamp(): Argument #2 ($min) must be smaller than or equal to argument #3 ($max)
The first call returns the right answer on 8.6 by accident. Working through the arithmetic, a ($min, $max, $value) helper called through the built-in either gives the same result or throws, because whenever the swapped bounds are in order, the answer comes out the same. So it fails loudly rather than returning wrong numbers. It throws for any value below the maximum, so a test suite only misses it if every value it passes is at or above the maximum. This is the kind of one-line helper nobody writes a test for, which is a good reason to write one anyway.
To find it before your users do:
grep -rn "function clamp" app/ src/ vendor/ wp-content/
The clamp RFC notes the change “could break potential userland implementations”. SortDirection has the same problem as a global class name. The SortDirection RFC found 178 GitHub results for class or enum SortDirection, namespaced and not. Only the unnamespaced ones clash.
Session defaults moved
UPGRADING (checked 20 November 2026) lists the new defaults. On the official images, which load no php.ini at all (Loaded Configuration File: (none)), ini_get() gives:
8.5.13 8.6.0
session.use_strict_mode '0' '1'
session.cookie_httponly '0' '1'
session.cookie_samesite '' 'Lax'
HttpOnly stops JavaScript reading the session cookie. SameSite=Lax stops the browser sending it on cross-site POSTs. Strict mode rejects session IDs the server did not create. All three are what you want, and the bundled php.ini-production in the 8.6 image already sets the same values. If your server uses that file, or sets these keys itself, nothing changes.
What can break is a flow that relied on the old defaults: a payment provider or SSO login that POSTs back to your site from another domain and expects the session to still be there. These settings only apply to PHP’s native sessions, so code that never calls session_start() is not affected.
Partial application
This is the change you will type most. A call with ? in place of an argument does not run the function. It returns a closure that waits for the missing argument. The release page’s example:
$supportsPfa = array_filter(
$versions,
version_compare(?, '8.6', '>='),
);
On ['8.4', '8.5', '8.6', '8.7', '9.0'] that returned 8.6, 8.7 and 9.0. The closure is a real one with a real signature. ReflectionFunction printed it as static function {closure:pfa:...} with one required parameter, string $version1, carried over from version_compare(), and a return type of int|bool.
Some behaviour from the RFC that is worth knowing before you use it everywhere, each checked on 8.6.0:
- Arguments are evaluated when the closure is created. With
$n = 1; $f = max($n, ?); $n = 100;, calling$f(5)returned5. An arrow function would have captured$nby value too, so this matches what you would expect fromfn, but it is not “call later with whatever is current”. - Extra arguments are dropped unless you add
....str_replace(' ', '-', ?)called with('a b', 'extra')returned"a-b". - Too few is an
ArgumentCountError: “Too few arguments to function {closure:pfa:/work/try.php:14}(), 0 passed … and exactly 1 expected”. - No
new. A file containingnew ArrayObject(?)does not run at all: “Fatal error: Cannot create Closure for new expression”. Static factory methods are fine:DateTimeImmutable::createFromFormat('Y-m-d', ?)andTime\Duration::fromMilliseconds(?)both worked as partials.
For everyday code, this mostly means array_map(str_pad(?, 5, '.'), $items) instead of array_map(fn ($s) => str_pad($s, 5, '.'), $items). It is shorter, and the parameter types come from the real function instead of being left off the arrow function.
Smaller things worth using
clamp() itself works on anything comparable. clamp(1.5, 0, 1) returned int(1) (the bound, with the bound’s type), and clamp('m', 'a', 'f') returned "f". A NAN value came back as NAN. A NAN bound throws a ValueError, according to the RFC (not run here).
Readonly property defaults let a readonly class set a constant-ish value without a constructor: public string $parser = 'SlugParser';. The default counts as the one initialisation, so a constructor that assigns it again throws Cannot modify readonly property Overrider::$mode. That is the RFC’s intended behaviour, not a bug, but it means you cannot use a default as a fallback that the constructor sometimes overrides.
SortDirection is an enum with two cases, Ascending and Descending. It is a unit enum, not backed, so there is no SortDirection::from('asc') for request input. Nothing built in accepts it yet either; the RFC leaves functions like scandir() for later. It is for your own signatures, so a query builder can reject SORT_STRING with a TypeError instead of an UnhandledMatchError halfway through.
Time\Duration replaces “all delays are in microseconds” comments. Duration::fromMilliseconds(100)->multiplyBy(2 ** 3)->add(Duration::fromSeconds(1)) gave seconds: 1, nanoseconds: 800000000. Durations work with <, >, min() and clamp(), but not +: $a + $b is TypeError: Unsupported operand types. ISO 8601 parsing takes time parts only: PT1H30M gave 5,400 seconds, and P1D threw Time\TimeException: “The ISO 8601 duration string may only contain the time (T) aspect”. The Duration RFC makes hours the largest unit.
Io\Poll picks epoll, kqueue, event ports or WSAPoll automatically, where stream_select() is built on select(), which the release page says “typically can’t handle more than 1024 connections”. class_exists('Io\Poll\Context') is true on 8.6.0, but the API was not exercised here. It matters if you write an event loop or a socket server yourself.
Deprecations you will see in logs
Three ran on 8.6.0 and printed:
Deprecated: Returning from a finally block is deprecated
Deprecated: Function is_integer() is deprecated since 8.6, use is_int() instead
Deprecated: Function spl_object_hash() is deprecated since 8.6, consider using spl_object_id() instead
The full list in UPGRADING also covers is_long(), is_double(), doubleval(), the mbstring regex functions (mb_ereg(), mb_split() and the rest), strcoll() and SORT_LOCALE_STRING, and the third argument to define(). One more behaviour change you may trip over: trim() now strips form feed (\f) by default. trim("\fname\f") is "name" on 8.6.0 and still six bytes on 8.5.13.
Before you upgrade
Run three things. In your project root, including vendor/:
grep -rn "function clamp\|class SortDirection" --include=*.php .
docker run --rm -v "$PWD":/app -w /app php:8.6-cli vendor/bin/phpunit
And on the server you will upgrade:
php -r 'foreach (["use_strict_mode", "cookie_httponly", "cookie_samesite"] as $k) echo $k, "=", var_export(ini_get("session.$k"), true), "\n";'
The grep finds the collisions. The test run tells you whether anything else moved, as long as the image has the extensions your project needs. If the last command prints '0', '0' and '' today and no php.ini sets those keys, your session cookies will change on upgrade. Then pick one array_filter with a throwaway closure and rewrite it with ?.
Comments