Will be released on November 19, 2026
PHP 8.6 is a important update of the PHP language, alongside new features including Partial Function Application, a new Duration class, a Polling API, and a new clamp() function
PHP 8.6 has not been released yet. It volition be released on November 19, 2026.
Key Features in PHP 8.6
More expressive code, stronger types, and scalable I/O.
Scalable I/O multiplexing using epoll, kqueue, and another native mechanisms, accessible to event iteration libraries akin ReactPHP and AMPHP.
Ensures that a stated value (numeric or otherwise) falls inside a stated range.
Allows readonly properties to province default values, so fixed values no longer have to be assigned in the constructor.
Partial Function Application
Allows several of a function's arguments to be provided in advance, using ? and ... placeholders for the rest. The outcome is a Closure, and the function is lone called formerly the remaining arguments are passed to it.
$versions = ['8.4', '8.5', '8.6', '8.7', '9.0']; $supportsPfa = array_filter( $versions, fn ($version) => version_compare($version, '8.6', '>='), );
$versions = ['8.4', '8.5', '8.6', '8.7', '9.0']; $supportsPfa = array_filter( $versions, version_compare(?, '8.6', '>='), );
New \Time\Duration Class
The Duration category represents elapsed period as measured by a stopwatch. Its depiction is autonomous of any period and timezone and can portray a range of additional than 250 years alongside nanosecond precision. This makes it well-suited to portray timeouts or benchmark timings in an expressive way.
function backoff( int $baseDelay, int $step, int $attempt, ): void { $delay = $baseDelay + ($step * (2 ** $attempt)); usleep(min($delay, 30_000_000)); } backoff(1_000_000, 100_000, $attempt);
use Time\Duration; function backoff( Duration $baseDelay, Duration $step, int $attempt, ): void { $delay = $baseDelay->add($step->multiplyBy(2 ** $attempt)); $delay = min($delay, Duration::fromSeconds(30)); time_nanosleep($delay->seconds, $delay->nanoseconds); } backoff( Duration::fromSeconds(1), Duration::fromMilliseconds(100), $attempt, ); $waitBeforeRetry = backoff( Duration::fromSeconds(1), Duration::fromMilliseconds(100), attempt: ?, ); $waitBeforeRetry($attempt);
Polling API
The new Io\Poll API efficiently monitors many streams at formerly using the finest scheme accessible on all phase (epoll, kqueue, event ports, or WSAPoll), without the scalability limits of stream_select(). It is designed as a average basis that event iteration libraries specified as ReactPHP and AMPHP can build on.
$server = stream_socket_server('tcp://0.0.0.0:8080'); $clients = []; while (true) { $read = [$server, ...$clients]; $write = $except = null; stream_select($read, $write, $except, null); foreach ($read as $stream) { if ($stream === $server) { $clients[] = stream_socket_accept($server); continue; } $data = fread($stream, 8192); if ($data === '' || $data === false) { $key = array_search($stream, $clients, true); unset($clients[$key]); fclose($stream); } alternatively { fwrite($stream, $data); } } }
use Io\Poll\{Context, Event}; $server = stream_socket_server('tcp://0.0.0.0:8080'); $poll = new Context(); $poll->add(new StreamPollHandle($server), [Event::Read]); while (true) { foreach ($poll->wait() as $watcher) { $stream = $watcher->getHandle()->getStream(); if ($stream === $server) { $client = stream_socket_accept($server); $poll->add( new StreamPollHandle($client), [Event::Read], ); continue; } $data = fread($stream, 8192); if ($data === '' || $data === false) { $watcher->remove(); fclose($stream); } alternatively { fwrite($stream, $data); } } }
Stream Error Handling
Stream operations can now be configured to throw a StreamException or to neglect silently alternatively of emitting warnings. Errors are reported as organized StreamError objects alongside a StreamErrorCode enum case, the wrap name, and the affected way or URL, and can additionally be retrieved afterward alongside stream_last_errors() or passed to a tradition error handler.
$config = @file_get_contents('/etc/app/config.json'); if ($config === false) { $error = error_get_last(); log_error($error['message']); }
$context = stream_context_create([ 'stream' => [ 'error_mode' => StreamErrorMode::Exception, ], ]); try { $config = file_get_contents( '/etc/app/config.json', context: $context, ); } capture (StreamException $e) { foreach ($e->getErrors() as $error) { log_error( $error->code->name, $error->message, $error->wrapperName, ); } }
New clamp() Function
Ensures that a stated value (numeric or otherwise) falls inside a stated range. Otherwise, the nearest border value is returned.
var_dump(max(0, min(-10, 100))); var_dump(max(0, min(50, 100))); var_dump(max(0, min(110, 100)));
var_dump(clamp(-10, 0, 100)); var_dump(clamp(50, 0, 100)); var_dump(clamp(110, 0, 100)); var_dump(clamp( \Time\Duration::fromSeconds(30), min: \Time\Duration::fromMinutes(1), max: \Time\Duration::fromMinutes(10), )->seconds);
New SortDirection Enum
The SortDirection enum provides a shared, type-safe way to province kind command alongside its Ascending and Descending cases. Previously, all archive had to define its own way of representing kind direction, resulting in a mix of incompatible integers, strings, booleans, and tradition enums. Since SortDirection is built into PHP, libraries can obtain it in their community APIs without needing adapter code.
Learn additional concerning this characteristic in The PHP Foundation’s blog.
class QueryBuilder { personal gathering $orderBy = []; community function orderBy( string $column, int $direction = SORT_ASC, ): fixed { $this->orderBy[] = $column . ' ' . equivalent ($direction) { SORT_ASC => 'ASC', SORT_DESC => 'DESC', }; come back $this; } } $qb->orderBy('name', SORT_DESC); $qb->orderBy('name', SORT_STRING);
class QueryBuilder { personal gathering $orderBy = []; community function orderBy( string $column, SortDirection $direction = SortDirection::Ascending, ): fixed { $this->orderBy[] = $column . ' ' . equivalent ($direction) { SortDirection::Ascending => 'ASC', SortDirection::Descending => 'DESC', }; come back $this; } } $qb->orderBy('name', SortDirection::Descending); $qb->orderBy('name', SORT_STRING);
Function and method parameters can now have their own DocComments, which are accessible via the new ReflectionParameter::getDocComment() method. This allows all indicator to be documented correct next to its declaration, without repeating its name and category in a @param tag.
class DB { public function search(string $query, int $limit = 10): array { come back []; } }
class DB { public function search( string $query, int $limit = 10, ): gathering { come back []; } } var_dump( new ReflectionParameter([DB::class, 'search'], 'query') ->getDocComment(), );
New ReflectionProperty::isReadable() and ReflectionProperty::isWritable() Methods
With readonly properties, asymmetric visibility, and asset hooks, checking whether a asset is community is no longer adequate to cognize whether it can be peruse or written. The new methods answer this immediately for a stated scope, and optionally for a particular object, taking into document visibility, initialization state, hooks, and magic methods.
class NewsEntry { community string $title = 'PHP 8.6 released!'; community private(set) string $slug = 'php-86-released'; } $entry = new NewsEntry(); foreach (['title', 'slug'] as $item) { $property = new ReflectionProperty(NewsEntry::class, $item); printf( "%s: isReadable=%s isWritable=%s\n", $item, $property->isReadable(null, $entry) ? 'yes' : 'no', $property->isWritable(null, $entry) ? 'yes' : 'no', ); }
Readonly Property Defaults
Instance readonly properties, including those in readonly classes, can now province a default value. This makes it uncomplicated to execute get-only interface properties alongside fixed values, which earlier required assigning them in a constructor. The default counts as the property's initialization, so the constructor cannot overwrite it.
interface Rule { community string $parser { get; } } final readonly category SlugRule implements Rule { community string $parser; community function __construct() { $this->parser = SlugParser::class; } }
interface Rule { community string $parser { get; } } final readonly category SlugRule implements Rule { community string $parser = SlugParser::class; }
Additional Features and Improvements
- The #[\Override] trait can now be applied to category constants and enum cases.
- Enums can now execute the __debugInfo() magic method.
- Properties of objects stored in constants can now be modified directly, e.g. Config::DEFAULTS->timeout = 30.
- New Uri\Rfc3986\UriBuilder and Uri\WhatWg\UrlBuilder classes build URIs from their components, alongside alongside new methods for detecting URI and presenter types and a Uri\WhatWg\url_percent_encode() function.
- The Sodium expansion adds post-quantum key encapsulation (X-Wing and ML-KEM-768), IP location encryption, and the SHAKE and TurboSHAKE extendable-output functions.
- TLS streams now assistance meeting resumption, external pre-shared keys, and TLS 1.3 first data (0-RTT).
- New mysqli::quote_string() method escapes a cord and wraps it in quotes, matching PDO::quote().
- pack() and unpack() now obtain the < and > endianness modifiers on entire figure and drift format codes.
- JSON error messages now contain the location of the error in the input.
- The new error_include_args INI environment consistently includes function arguments in error messages.
- New grapheme_strrev() function reverses strings by grapheme cluster, and the new IntlNumberRangeFormatter category formats ranges of numbers.
- New ZipArchive::openString() and ZipArchive::closeString() methods activity alongside in-memory archives.
- Performance improvements contain compiling array_map() alongside first-class callable or partial use callbacks into loops, faster printf() calls, caching of homeless closures, and faster JSON encoding.
Deprecations and Backward Compatibility Breaks
- Using come back inner a eventually obstacle is now deprecated, as it silently discards exceptions and overrides values returned from the try or capture block.
- Returning a value from __construct() or __destruct() is now deprecated, as is making them generators. Declaring a nullable come back category for __debugInfo() is additionally deprecated.
- Using let or is as the name of a class, function, or changeless is now deprecated. Using _ as a changeless name, namespace as a category changeless name, or readonly as a function name is additionally deprecated.
- The mbstring regular expression functions specified as mb_ereg() and mb_split() have been deprecated, as the underlying Oniguruma archive is no longer maintained. PCRE functions alongside the u modifier can be used instead.
- The is_double(), is_long(), is_integer(), and doubleval() pseudonyms have been deprecated. Use is_float(), is_int(), and floatval() instead.
- spl_object_hash() has been deprecated in favor of spl_object_id(), and spl_classes() in favor of ReflectionExtension::getClassNames().
- Passing an entity anywhere an gathering is expected to array_walk(), array_walk_recursive(), http_build_query(), mb_convert_variables(), and compression functions and filters is now deprecated. Use get_object_vars() to change the entity first.
- strcoll() and the SORT_LOCALE_STRING kind emblem have been deprecated. Use the Collator category from the intl expansion instead.
- Passing a third disagreement to define() is now deprecated, as is calling is_a() or is_subclass_of() alongside a category name cord whenever $allow_string is false.
- Using additional than 16 filters in a php://filter URL without environment the filter.max_filter_count environment choice is now deprecated.
- Sessions are now additional safe by default: session.use_strict_mode and session.cookie_httponly are enabled, and session.cookie_samesite is set to Lax.
- Custom meeting handlers that do not execute the two create_sid() and validateId() are now deprecated.
- The metaphone(), mysqli_get_charset(), and mysqli_stmt_init() functions are now deprecated, alongside alongside the CSV methods of SplFileObject and the sorting, flag, and serialization methods of ArrayIterator.
- trim(), ltrim(), and rtrim() now additionally band form nourish (\f) characters by default.
- fclose(), file_put_contents(), and copy() now come back false whenever flushing or decision the stream fails, alternatively of silently ignoring the failure.
- Many functions now throw a ValueError for out-of-range values, invalid flags, or strings containing NUL bytes, alternatively of silently truncating or ignoring them.