PHP 8.6 upgrade: new features and the breaking changes to check
PHP 8.6 was released on 19 November 2026 with partial function application, a Duration class, the Io\Poll API, clamp() and a SortDirection enum. The upgrade risks are in the details, notably stricter session cookie defaults, new ValueErrors, form feeds stripped by trim() and a batch of deprecations.
PHP 8.6 was released on 19 November 2026. The headline features are partial function application, a \Time\Duration class, a new Io\Poll API and a clamp() function. For most teams the more urgent part is the backward-incompatible changes list: session cookies are stricter by default, many functions now throw instead of silently truncating, and trim() strips one more character. This post covers what's new and what to test first.
The new features worth knowing
Partial function application
You can now supply some of a function's arguments in advance, using ? and ... as placeholders. The result is a Closure, and the function only runs when the remaining arguments are passed. The release page's example:
$versions = ['8.4', '8.5', '8.6', '8.7', '9.0'];
$supportsPfa = array_filter(
$versions,
version_compare(?, '8.6', '>='),
);This replaces a lot of one-line fn ($v) => version_compare($v, '8.6', '>=') closures in callback-heavy code.
Duration, Io\Poll, clamp and SortDirection
\Time\Durationrepresents elapsed time "as measured by a stopwatch", with constructors such asDuration::fromSeconds()andDuration::fromMilliseconds(). Useful for timeouts and retry backoff, where bare integers invite unit mistakes.Io\Pollmonitors many streams at once using the best mechanism on each platform (epoll, kqueue, event ports or WSAPoll), without the scalability limits ofstream_select(). This matters for long-running workers and async libraries.clamp()keeps a value inside a range:clamp(-10, 0, 100)returnsint(0).SortDirectionis an enum withAscendingandDescendingcases, giving libraries a type-safe sort-order parameter instead of overloaded integer constants.
Readonly property defaults
Instance readonly properties, including those in readonly classes, can now declare a default value:
final readonly class SlugRule implements Rule
{
public string $parser = SlugParser::class;
}Breaking changes to test first
The full list is long. These are the ones most likely to surface in a typical web application.
Session defaults are stricter
Three session INI defaults changed:
| Setting | Before | PHP 8.6 |
|---|---|---|
session.use_strict_mode | 0 | 1 |
session.cookie_httponly | 0 | 1 |
session.cookie_samesite | unset | "Lax" |
These are better defaults, but each can break something. Custom session handlers that accept externally supplied IDs must now implement validateId() and create_sid(), or set strict mode back to 0. JavaScript that reads the session cookie will stop working. Flows that rely on a cross-site POST carrying the session, such as some payment or SSO callbacks, need session.cookie_samesite = "None" together with session.cookie_secure = 1.
If you set these explicitly in php.ini or with ini_set(), nothing changes for you. Check what you rely on implicitly:
php -i | grep -E 'session\.(use_strict_mode|cookie_httponly|cookie_samesite)'There are two smaller session changes too. session_encode() now returns "" instead of false for an empty session. With session.lazy_write on and a handler implementing SessionUpdateTimestampHandlerInterface, empty sessions now call updateTimestamp() instead of write(), so handlers that destroyed sessions in write() need that logic moved.
Throwing instead of silently truncating
Many functions now raise a ValueError for out-of-range values, invalid flags or strings containing NUL bytes. Examples include getenv(), putenv(), parse_str(), setlocale(), the file_exists()/is_file()/stat() family, number_format() with an out-of-range decimals, and sleep() above UINT_MAX. Code that passes user input straight into filesystem checks without validating it will now throw where it used to return false.
Other changes that change results
trim(),ltrim()andrtrim()now strip form feed (\f) by default.trim("\f hello \f")returns"hello".fclose(),file_put_contents()andcopy()returnfalsewhen flushing or closing the stream fails, instead of ignoring the failure.preg_grep()returnsfalseinstead of a partial array on a PCRE execution error, such as malformed UTF-8 with theumodifier.- In
unpack(),<or>right after a format code is now an endianness modifier:'s<value'yields a key namedvalue, not<value. - With PDO_PGSQL persistent connections, session state such as
SETvalues and temporary tables is reset when the last PDO object using the connection is destroyed. - Fileinfo reports TrueType fonts as
font/ttfinstead offont/sfnt, which can affect upload allow-lists. ??andempty()on a magic property no longer call__get()when__isset()has written the property.
Deprecations to clean up
Deprecations don't break anything yet, but they fill logs and will become errors later:
returninside afinallyblock.- Returning a value from
__construct()or__destruct(), or making them generators. - The mbstring regex functions such as
mb_ereg()andmb_split(), because the Oniguruma library they use is no longer maintained. - The
is_double(),is_long(),is_integer()anddoubleval()aliases. Useis_float(),is_int()andfloatval(). spl_object_hash()in favour ofspl_object_id(), andspl_classes()in favour ofReflectionExtension::getClassNames().
The alias deprecations are mechanical find-and-replace work. The mb_ereg() family needs real rewrites to preg_* functions, so find those early.
A practical upgrade plan
- Check your dependencies.
composer why-not php 8.6.0lists packages whose constraints block the upgrade. - Add PHP 8.6 to CI alongside your current version, with deprecations visible (
error_reporting=E_ALL) so the new notices show up in test output. - Pin session settings explicitly in your config, whichever values you choose, so behaviour doesn't depend on the PHP version.
- Grep for the risky calls:
mb_ereg,mb_split,is_double,is_long,is_integer,doubleval,spl_object_hash,unpack(, andfinallyblocks containingreturn. - Test sign-in and cross-site flows in a browser, not just unit tests. Cookie attribute changes only show up when a real browser enforces them.
That last step is where agent-driven upgrades often fall short: the diff looks fine and the unit tests pass, but a login callback breaks. CodeBeast's Test agent boots the app and works through the flows named in the plan in a real browser, which is the kind of check SameSite changes need.
Sources
FAQ
When was PHP 8.6 released?
PHP 8.6 was released on 19 November 2026. It is a minor version, which the PHP manual says brings new features and "a few incompatibilities that should be tested for before switching PHP versions in production environments."
What is partial function application in PHP 8.6?
It lets you call a function with some arguments filled in and ? or ... placeholders for the rest. Instead of running, the call returns a Closure that takes the missing arguments. It is a shorter alternative to wrapping a call in an arrow function.
Will PHP 8.6 break my sessions?
It might. session.use_strict_mode and session.cookie_httponly now default to on, and session.cookie_samesite defaults to Lax. Custom session handlers, JavaScript that reads the session cookie and cross-site POST flows are the usual places this shows up.
Is mb_ereg deprecated in PHP 8.6?
Yes. The mbstring regular expression functions, including mb_ereg() and mb_split(), are deprecated because the underlying Oniguruma library is no longer maintained. Plan to move that code to the preg_* functions.
Written by the CodeBeast Team with AI assistance. Spotted a mistake? Email support@codebeast.ai.