PHP 8.6 Preview: Partial Function Application, clamp(), Duration & Polling API

PHP 8.6, slated for November 19, 2026, introduces partial function application with ? and ... placeholders, a clamp() function for value bounding, a Time\Duration class with nanosecond precision, readonly property defaults, parameter doc comments, an Io\Poll API for I/O multiplexing, SortDirection enum, enum __debugInfo(), unified stream error handling, URI builder enhancements, and stricter session security defaults.

21CTO
21CTO
21CTO
PHP 8.6 Preview: Partial Function Application, clamp(), Duration & Polling API

Release Timeline

PHP 8.6 GA scheduled for November 19, 2026. Beta started August 13, 2026; feature freeze September 22; RC1 September 24; RC4 November 5. Release managers: Daniel Scherzer, Matteo Beccati, Joe Ferguson.

Partial Function Application (PFA)

Allows pre-filling some function parameters, returning a closure accepting remaining parameters. Uses ? for single subsequent parameter placeholder and ... for rest parameters. Generated closure retains original parameter names, types, and defaults. Pre-filled arguments are evaluated at partial application time, not at closure call. Each ? placeholder becomes a required parameter in the closure even if original was optional. The proposal was rejected in 2021; second RFC passed 33-0.

$makeSlug = str_replace(' ', '-', ?);
$makeSlug('Hello World'); // Hello-World
$titles = array_map(strtolower(?), $titles);

clamp() Function Family

New clamp() returns value if within min/max bounds, else nearest boundary. Supports all comparable types: integers, floats, strings, DateTime objects. Throws ValueError if min > max. Replaces error-prone min(max($value, $min), $max) pattern.

clamp(10, min: 0, max: 100); // 10
clamp(101, min: 0, max: 100); // 100
clamp(-1, min: 0, max: 100); // 0

Time\Duration Class

New final readonly class Time\Duration represents stopwatch-style durations with nanosecond precision. Provides factory methods for each time unit, arithmetic operations (add, subtract, multiply, divide), and comparison operators. Can be constructed from ISO 8601 duration strings. Intended as standard type for kernel and new polling API, replacing loose integer/float time values.

use Time\Duration;
$oneSecond = Duration::fromSeconds(1);
$halfSecond = $oneSecond->divideBy(2);
$total = $oneSecond->add($halfSecond);
$delay = Duration::fromMilliseconds(100)->multiplyBy(2 ** $attempt);
$total > $delay; // direct comparison

Readonly Properties with Default Values

PHP 8.6 allows default values on readonly properties, previously a compile error. This simplifies implementing readonly interface properties with fixed defaults. Readonly semantics unchanged: cannot be reassigned after initialization.

final readonly class CreateBooksTable implements Migration {
    public string $name = '2026_01_01_create_books_table';
}

Function Parameter Doc Comments

Parameters can now have inline doc comments, readable via ReflectionParameter::getDocComment(). Eliminates need to repeat parameter names in function-level @param tags. Static analysis tools and IDEs can read these directly.

function search(
    /** Terms to search for in the database */
    string $query,
    /** Maximum number of entries to return */
    int $limit = 10,
): array {
    // ...
}

Io\Poll Polling API

New Io\Poll namespace provides unified I/O multiplexing interface: epoll (Linux), kqueue (BSD/macOS), event ports (Solaris), WSAPoll (Windows). Replaces stream_select() for user-space event loops and async runtimes. Primary goal: internal PHP use (signal handling, FPM improvements); secondary: user-space async frameworks.

use Io\Poll\{Context, Event, StreamPollHandle};
$poll = new Context();
$server = stream_socket_server('tcp://0.0.0.0:8080');
stream_set_blocking($server, false);
$poll->add(new StreamPollHandle($server), [Event::Read], ['type' => 'server']);
while (true) {
    foreach ($poll->wait(1) as $watcher) {
        if ($watcher->hasTriggered(Event::Read)) {
            // accept the connection
        }
    }
}

SortDirection Enum

Built-in global enum SortDirection with cases Ascending and Descending. Provides standard type to avoid libraries defining custom sort enums; typical use in query builders. No kernel functions yet accept it directly.

$query->orderBy('created_at', SortDirection::Descending);

Enum __debugInfo() Magic Method

PHP 8.6 allows enums to implement __debugInfo() to customize var_dump() output. Previously most magic methods were prohibited on enums.

enum Status: int {
    case Ok = 200;
    public function __debugInfo(): array {
        return [__CLASS__ . '::' . $this->name . ' = ' . $this->value];
    }
}

Stream Unified Error Handling Model

Streams gain unified error model. New error_mode context option: warning, exception, or silent. stream_last_errors() returns structured StreamError objects for last operation. StreamErrorCode enum defines 50+ semantic error codes.

$context = stream_context_create([
    'stream' => ['error_mode' => StreamErrorMode::Exception],
]);
try {
    $stream = fopen('/nonexistent/file.txt', 'r', false, $context);
} catch (StreamException $e) {
    foreach ($e->getErrors() as $error) {
        echo $error->code->name . ': ' . $error->message;
    }
}

URI Extension Enhancements (Continued from PHP 8.5)

PHP 8.5 introduced URI extension with Uri\Rfc3986\UriBuilder for fluent URI assembly without intermediate objects. PHP 8.6 adds getUriType(), getHostType(), and percent-encoding functions for URI components.

$uri = new Uri\Rfc3986\UriBuilder()
    ->setScheme('https')
    ->setHost('example.com')
    ->setPath('/foo/bar')
    ->build();

Session Security Default Changes

Fresh installs update three php.ini session defaults: session.use_strict_mode from 0 to 1 session.cookie_httponly from 0 to 1 session.cookie_samesite from unset to Lax Laravel applications unaffected as framework manages session cookies. Native session users relying on old defaults should review Session defaults RFC.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Session SecurityclampDurationPartial Function ApplicationPHP 8.6Polling APIStream Error HandlingSortDirection
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.