PHP 8.6 was released on November 19, 2026. It brings a placeholder syntax that turns function calls into closures, a stopwatch-style Time\Duration class, a built-in clamp() function, a scalable polling API for event loops, and several long-awaited quality-of-life improvements. It also deprecates a number of old functions and makes sessions more secure by default, so it is worth reading the upgrade notes before you bump your PHP version.
Table of Contents
ToggleQuick summary
- Partial function application: ? and … placeholders create closures.
- Time\Duration: a readonly class for elapsed time with nanosecond precision.
- clamp(): keeps a value inside a range.
- Polling API (Io\Poll): epoll, kqueue, event ports or WSAPoll behind one API.
- SortDirection enum: one shared, type-safe way to express sort order.
- Readonly property defaults: no constructor needed for fixed values.
- Also new: structured stream errors, parameter DocComments, ReflectionProperty::isReadable() and isWritable(), post-quantum Sodium, and more.
- Heads up: several deprecations and new session defaults.
1. Partial function application
You can now supply some of a function’s arguments up front and leave the rest as placeholders: ? for a single argument and … for the remaining ones. The result is a Closure, and the original function only runs once the missing arguments are passed in.
Before (PHP 8.5 and older):
$versions = ['8.4', '8.5', '8.6', '8.7', '9.0'];
$supportsPfa = array_filter(
$versions,
fn ($version) => version_compare($version, '8.6', '>='),
);
PHP 8.6:
$supportsPfa = array_filter(
$versions,
version_compare(?, '8.6', '>='),
);
The ? marks the argument that will be supplied later. No more wrapping a call in an arrow function just to fix a couple of arguments. The release notes also mention that array_map() calls using partial application callbacks can be compiled into loops, which helps performance.
2. The new Time\Duration class
Time\Duration represents elapsed time as measured by a stopwatch. It is independent of any time or timezone, covers a range of more than 250 years, and has nanosecond precision, which makes it a good fit for timeouts and benchmark timings. The class is a final readonly class, so instances never change.
use Time\Duration;
function backoff(
Duration $baseDelay,
Duration $step,
int $attempt,
): void {
$delay = $baseDelay->add($step->multiplyBy(2 ** $attempt));
// Durations are comparable, so min() works directly.
$delay = min($delay, Duration::fromSeconds(30));
time_nanosleep($delay->seconds, $delay->nanoseconds);
}
backoff(
Duration::fromSeconds(1),
Duration::fromMilliseconds(100),
$attempt,
);
// Durations are comparable, so min() works directly.
$delay = min($delay, Duration::fromSeconds(30));
time_nanosleep($delay->seconds, $delay->nanoseconds);
}
backoff(
Duration::fromSeconds(1),
Duration::fromMilliseconds(100),
$attempt,
);
Compare that with the old style of passing raw microsecond integers to usleep() and hoping everyone remembers the unit. Durations are self-describing, and you can combine them with partial function application:
$waitBeforeRetry = backoff(
Duration::fromSeconds(1),
Duration::fromMilliseconds(100),
attempt: ?,
);
$waitBeforeRetry($attempt);
3. The new clamp() function
clamp() makes sure a value falls within a range. If it doesn’t, you get the nearest boundary. The argument order is value, minimum, maximum.
Before:
var_dump(max(0, min(110, 100))); // int(100)
PHP 8.6:
var_dump(clamp(-10, 0, 100)); // int(0)
var_dump(clamp(50, 0, 100)); // int(50)
var_dump(clamp(110, 0, 100)); // int(100)
It works with any comparable value, not just numbers, so it also works with the new Duration class:
var_dump(clamp(
\Time\Duration::fromSeconds(30),
min: \Time\Duration::fromMinutes(1),
max: \Time\Duration::fromMinutes(10),
)->seconds);
// int(60)
4. The Polling API (Io\Poll)
The new Io\Poll API monitors many streams at once using the best mechanism available on each platform: epoll, kqueue, event ports or WSAPoll. It avoids the scalability limits of stream_select(), which typically can’t handle more than 1024 connections.
use Io\Poll\{Context, Event};
$server = stream_socket_server('tcp://0.0.0.0:8080');
// Automatically uses epoll, kqueue, event ports, or WSAPoll
$poll = new Context();
$poll->add(new StreamPollHandle($server), [Event::Read]);
while (true) {
foreach ($poll->wait() as $watcher) {
$stream = $watcher->getHandle()->getStream();
// handle the readable stream here
}
}
This is designed as a common foundation that event loop libraries such as ReactPHP and AMPHP can build on, so most application developers will benefit indirectly through those libraries.
5. The SortDirection enum
Every library used to invent its own way to express sort order: integers, strings, booleans or custom enums. PHP 8.6 adds a built-in SortDirection enum with Ascending and Descending cases, so libraries can accept it in public APIs without adapter code.
public function orderBy(
string $column,
SortDirection $direction = SortDirection::Ascending,
): static {
// ...
}
$qb->orderBy('name', SortDirection::Descending);
$qb->orderBy('name', SORT_STRING);
// TypeError: Argument #2 ($direction) must be of type SortDirection, int given
6. Readonly property defaults
Instance readonly properties, including those in readonly classes, can now declare a default value. That makes get-only interface properties with fixed values much simpler.
Before:
interface Rule
{
public string $parser { get; }
}
final readonly class SlugRule implements Rule
{
public string $parser;
public function __construct()
{
$this->parser = SlugParser::class;
}
}
PHP 8.6:
final readonly class SlugRule implements Rule
{
public string $parser = SlugParser::class;
}
The default counts as the property’s initialization, so a constructor cannot overwrite it.
7. Structured stream error handling
Stream operations can now be configured to throw a StreamException, or to fail silently, instead of emitting warnings. Errors come back as structured StreamError objects with a StreamErrorCode enum case, the wrapper name and the affected path or URL. You can also fetch them later with stream_last_errors().
$context = stream_context_create([
'stream' => [
'error_mode' => StreamErrorMode::Exception,
],
]);
try {
$config = file_get_contents('/etc/app/config.json', context: $context);
} catch (StreamException $e) {
foreach ($e->getErrors() as $error) {
log_error($error->code->name, $error->message, $error->wrapperName);
}
}
No more silencing with @ and parsing a message string from error_get_last().
8. Reflection and DocComment improvements
DocComments for parameters. Parameters can now have their own DocComments, available through the new ReflectionParameter::getDocComment() method, so you can document a parameter right next to its declaration:
class DB
{
public function search(
/** Terms to search */
string $query,
/** Maximum number of results */
int $limit = 10,
): array {
return [];
}
}
Readable and writable checks. With readonly properties, asymmetric visibility and property hooks, checking that a property is public no longer tells you whether you can read or write it. The new ReflectionProperty::isReadable() and isWritable() methods answer that directly for a given scope, taking visibility, initialization state, hooks and magic methods into account.
9. Other improvements
- The
#[\Override]attribute can now be applied to class constants and enum cases. - Enums can implement the
__debugInfo()magic method. - Properties of objects stored in constants can be modified directly, for example
Config::DEFAULTS->timeout = 30. - New
Uri\Rfc3986\UriBuilderandUri\WhatWg\UrlBuilderclasses build URIs from their components. - Sodium adds post-quantum key encapsulation (X-Wing and ML-KEM-768), IP address encryption, and the SHAKE and TurboSHAKE functions.
- TLS streams support session resumption, external pre-shared keys and TLS 1.3 early data (0-RTT).
- JSON error messages now include the location of the error in the input.
- New
mysqli::quote_string()method, matchingPDO::quote(). pack()andunpack()accept the<and>endianness modifiers.- New
grapheme_strrev()function andIntlNumberRangeFormatterclass. - New
ZipArchive::openString()andZipArchive::closeString()for in-memory archives. - Performance improvements include faster
printf()calls, cached stateless closures and faster JSON encoding.
10. Deprecations and backward compatibility breaks
These are the changes most likely to affect existing projects.
Deprecated
- Using
returninside afinallyblock, because it silently discards exceptions and overrides values fromtryorcatch. - The mbstring regex functions such as
mb_ereg()andmb_split(). Use PCRE functions with theumodifier instead. - The aliases
is_double(),is_long(),is_integer()anddoubleval(). Useis_float(),is_int()andfloatval(). spl_object_hash()in favor ofspl_object_id(), andspl_classes()in favor ofReflectionExtension::getClassNames().strcoll()and theSORT_LOCALE_STRINGflag. Use theCollatorclass from the intl extension.- Passing a third argument to
define(). - Returning a value from
__construct()or__destruct(), or making them generators. - Using
letorisas a class, function or constant name. - Custom session handlers that don’t implement both
create_sid()andvalidateId(). metaphone(),mysqli_get_charset()andmysqli_stmt_init().
Behavior changes
- Sessions are more secure by default:
session.use_strict_modeandsession.cookie_httponlyare enabled, andsession.cookie_samesiteis set toLax. trim(),ltrim()andrtrim()now also strip form feed (\f) characters by default.fclose(),file_put_contents()andcopy()now returnfalsewhen flushing or closing the stream fails.- Many functions now throw a
ValueErrorfor out-of-range values, invalid flags or strings containing NUL bytes, instead of silently truncating or ignoring them.
Upgrade checklist
- Move to the latest PHP 8.5.x first and fix any deprecation warnings you already have.
- Run your test suite on PHP 8.6 with
error_reportingset toE_ALLso new deprecations show up. - Search your code for the deprecated functions listed above, especially
mb_ereg*, theis_double()family,spl_object_hash()andreturninsidefinally. - Review session code. If you relied on the old defaults, for example JavaScript reading the session cookie or cross-site cookie flows, set the options explicitly.
- Check places where a failed
fclose(),file_put_contents()orcopy()was previously ignored. - Confirm that your Composer packages and extensions support PHP 8.6 before upgrading production.
Final thoughts
PHP 8.6 is a strong release. Partial function application, clamp() and Time\Duration will change how everyday code reads, the Polling API lays the groundwork for faster event loops, and readonly defaults and SortDirection remove boilerplate. Test the deprecations before you upgrade and you should be fine.
Which PHP 8.6 feature are you most excited about? Tell me in the comments, and subscribe to the channel for more PHP and Laravel videos.
Sources: the official PHP 8.6 release announcement and Laravel News: PHP 8.6 release day