NEWS

PHP 8.6 Arrives with Partial Function Application, Duration, and a Polling API for I/O

PHP 8.6 Arrives with Partial Function Application, Duration, and a Polling API for I/O
Image: Redação iMasters
News
Reading
5 min
Tables
1
Code
3
In short

Released this Thursday (11/19), the major PHP version brings partial functions, a class for measuring time, scalable I/O with epoll/kqueue, and stricter security by default.

PHP 8.6.0 was released this Thursday, November 19, 2026, according to the official announcement from the language team. The version is presented as "faster, safer, and more powerful" and brings features such as Partial Function Application, the \Time\Duration class, a Polling API for scalable I/O, and the clamp() function. For those who maintain backend systems in production, the biggest impact isn't in day-to-day syntax, but in how code handles concurrency, time, and types across libraries.

Partial Function Application: closing arguments without creating a wrapper

Up through PHP 8.5, pre-configuring part of a function's arguments required writing a closure by hand or resorting to Closure::fromCallable() with workarounds. PHP 8.6 allows fixing arguments using ? and ... as placeholders, returning a Closure that only executes when the remaining arguments arrive:

php
function backoff(int $baseDelay, int $step, int $attempt): void {
 $delay = $baseDelay + ($step * (2 ** $attempt));
 usleep(min($delay, 30_000_000));
}

// Pre-configures the base delay and the increment,
// leaving only $attempt open.
$waitBeforeRetry = backoff(baseDelay: 1_000_000, step: 100_000, attempt: ?);
$waitBeforeRetry($attempt);

The practical gain is less boilerplate in functional code: validation pipelines, retry queues, and middleware composition no longer need an extra closure just to fix parameters.

\Time\Duration: no more counting microseconds by hand

The new Duration class represents elapsed time independent of time zone or date, with nanosecond precision and a range of over 250 years. It replaces the pattern of passing an int in microseconds (or milliseconds, depending on the function) and makes code self-explanatory:

php
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);
}

Anyone who has already suffered a unit bug (assuming a parameter was in milliseconds when it was actually in microseconds) gets a type that eliminates this ambiguity, especially useful for retries, queue timeouts, and internal benchmarks.

Polling API: an alternative to stream_select() for those writing servers

PHP servers that multiplex connections today rely on stream_select(), which in practice doesn't scale well beyond 1024 simultaneous connections on many systems. The new Io\Poll API uses the best native mechanism available on each platform, epoll on Linux, kqueue on BSD/macOS, event ports on Solaris, or WSAPoll on Windows, without that ceiling:

php
use Io\Poll\{Context, Event};

$poll = new Context(); // automatically selects epoll/kqueue/WSAPoll
$poll->add(new StreamPollHandle($server), [Event::Read]);

foreach ($poll->wait() as $watcher) {
 $stream = $watcher->getHandle()->getStream();
 // handle read or accept new connection
}

According to the announcement, the API was designed as a common foundation for event loop libraries such as ReactPHP and AMPHP, two projects widely used in Brazil in asynchronous PHP services and queue workers. This doesn't change the end application directly, but it tends to unlock scaling gains in these libraries without rewriting application code.

clamp(), SortDirection, and safer types across libraries

Two small additions solve recurring ergonomics and typing problems:

FeatureBeforeAfter
Limiting a value to a rangemax(0, min($v, 100))clamp($v, 0, 100)
Sort directionint/string per library, no standardSortDirection::Ascending / ::Descending, native enum

clamp() accepts any comparable value, including the new Duration. SortDirection, in turn, solves a concrete problem: today each query builder or ORM library invents its own constant for "ascending order," and passing the wrong value only breaks at runtime, inside a match. With the native enum in the method's signature, the error becomes a TypeError at call time, before the internal logic runs.

Readonly with default values and more introspection via Reflection

readonly properties can now declare a default value directly in the class, without needing to assign it in the constructor, which simplifies implementing "get-only" interfaces with a fixed value. In addition, ReflectionProperty gained isReadable() and isWritable(), which take into account asymmetric visibility (private(set)), property hooks, and initialization state, something that checking public alone no longer resolves since PHP introduced asymmetric visibility. Function parameters also now accept their own DocComment, retrievable via ReflectionParameter::getDocComment(), useful for documentation generators and IDEs that currently rely on manually parsing the @param block.

Security by default: sessions, post-quantum Sodium, and TLS

PHP 8.6 changes session defaults to reduce the attack surface without requiring configuration: session.use_strict_mode and session.cookie_httponly come enabled, and session.cookie_samesite becomes Lax by default. Custom session handlers that don't implement create_sid() and validateId() are deprecated. The Sodium extension gains post-quantum key encapsulation (X-Wing and ML-KEM-768) and IP address encryption, and TLS streams now support session resumption, external pre-shared keys, and TLS 1.3 0-RTT. For teams dealing with LGPD (Brazil's data protection law) and sensitive data, the more secure session defaults tend to close gaps in configurations that currently rely on manual hardening in each project.

What will break: deprecations to map before upgrading

The list of deprecations is long, and it's worth running in staging with full error_reporting before going to production:

  • return inside finally becomes deprecated, as it silently masks exceptions;
  • __construct()/__destruct() returning a value or becoming a generator is also deprecated;
  • let, is, _ as a constant name, namespace as a class constant, and readonly as a function name are deprecated;
  • mbstring's regex functions (mb_ereg(), mb_split()) are deprecated because Oniguruma is no longer maintained; the alternative is PCRE with the u modifier;
  • is_double(), is_long(), is_integer(), and doubleval() are deprecated in favor of is_float(), is_int(), and floatval();
  • spl_object_hash() gives way to spl_object_id();
  • passing an object where an array is expected in array_walk(), http_build_query(), and compression functions is deprecated;
  • strcoll() and the SORT_LOCALE_STRING flag are deprecated in favor of the intl extension's Collator class.

Many of these point to APIs that legacy PHP projects have used for years without revisiting, so it's worth grepping the repository before assuming the migration will be smooth.

Performance and what's left for later

The changelog cites concrete performance gains: array_map() calls with a first-class callable or with Partial Function Application now compile to a loop instead of call indirection, printf() got faster, stateless closures are now cached, and JSON encoding was optimized. None of these percentage gain figures are detailed in the official announcement, so anyone relying on specific performance needs to measure it on their own workload before promising results to a stakeholder. The full migration guide, including the list of compatibility breaks, is available in the PHP 8.6 release announcement.

Translated from the Brazilian Portuguese original · Read the original