What is new in PHP 8.6
PHP 8.6 in one page
PHP 8.6.0 was released on 19 November 2026. It is a feature release of the 8.x line: no new engine mode, no rewrite, just a long list of changes that remove small daily annoyances and close a few sharp edges.
The tested way to get it is the official image, which needs Docker:
docker run --rm php:8.6-cli php -v
Who should care: anyone who writes closures, value objects, enums or binary protocols, and anyone who maintains code that still calls the aliases and helpers that 8.6 deprecates. Framework users get the changes through the next minor release, but the deprecations reach ordinary code directly.
Every example below was run on PHP 8.6.0. The pages of this site run on the hosting PHP, which is 8.5 in the hosting-like images, so nothing in 8.6 syntax may be put in a live page yet. Section Our code to update lists what waits for the move.
Partial function application
A closure that only fills the first arguments of a function is noise. PHP 8.6 lets a call stop at a placeholder and returns a Closure: a single ? leaves that one argument open, and ... leaves all the remaining ones open. It works with userland and internal functions alike.
function add(int $a, int $b, int $c = 0): int { return $a + $b + $c; }
$addOne = add(1, ?);
var_dump($addOne(5));
$addToOne = add(1, ...);
var_dump($addToOne(2, 3));
$strip = str_replace(" ", "", ?);
var_dump($strip("a b c"));
var_dump(array_map(strtoupper(?), ["a", "b"]));
int(6) int(6) string(3) "abc" array(2) { [0]=> string(1) "A" [1]=> string(1) "B" }
Use it when a callback binds one fixed argument, as in a str_replace() stage of a pipeline or a mapper that only upper-cases its input.
Default values for readonly properties
A readonly property may now carry a default value, and that default counts as its single initialisation. It still cannot be reassigned, not even in the constructor.
class Config { public readonly int $timeout = 30; }
$c = new Config();
var_dump($c->timeout);
try { $c->timeout = 5; } catch (Error $e) { echo get_class($e), ": ", $e->getMessage(), "\n"; }
int(30) Error: Cannot modify readonly property Config::$timeout
Use it for a value object whose field has a real default, such as a timeout or a page size, instead of repeating the constant in every constructor call.
#[\Override] on constants
The #[\Override] attribute used to guard methods. PHP 8.6 accepts it on class constants and enum cases, and the compiler reports a constant that claims to override something that the parent or the interface does not define.
interface HasVersion { const VERSION = "1.0"; }
class Package implements HasVersion { #[\Override] const VERSION = "2.0"; }
echo Package::VERSION, "\n";
2.0
Without a matching parent constant the code does not compile:
class P { #[\Override] const NAME = "x"; }
Fatal error: P::NAME has #[\Override] attribute, but no matching parent constant exists in /e/override_const_missing.php on line 2 Stack trace: #0 {main}
Use it on every constant that intentionally replaces a parent value, so a renamed parent constant fails at build time, not at run time.
Enum __debugInfo()
An enum could not define __debugInfo() before: the engine treated it as a fatal error. PHP 8.6 allows the method, so var_dump() shows the fields that matter instead of the raw case.
enum Suit: string {
case Hearts = "H"; case Spades = "S";
public function __debugInfo(): array { return ["suit" => $this->name, "symbol" => $this->value]; }
}
var_dump(Suit::Hearts);
enum(Suit::Hearts) (2) { ["suit"]=> string(6) "Hearts" ["symbol"]=> string(1) "H" }
Use it when a backed enum carries a label or a symbol and a dump should read like the domain, not like the engine.
Objects in constants
A constant can hold an object, but until 8.6 the object was frozen. PHP 8.6 allows mutating it: the constant binding stays, the object state changes.
const CONFIG = new stdClass();
CONFIG->debug = true;
var_dump(CONFIG->debug);
bool(true)
Use it for a process-wide settings object that starts from a literal default and is adjusted during bootstrap. The constant itself is still not reassignable.
clamp()
Keeping a number inside a range took max($min, min($max, $value)) or the other way round, and the two forms were easy to mix up. clamp() takes the value, the low bound and the high bound, in that order, and works for integers and floats.
var_dump(clamp(15, 0, 10), clamp(-3, 0, 10), clamp(5, 0, 10), clamp(2.5, 0.0, 1.0));
int(10) int(0) int(5) float(1)
Use it for percentages, opacity, volume and any other value that has a hard floor and ceiling.
Time\Duration
Durations travelled as bare integers with the unit in the variable name. Time\Duration is an immutable, comparable value object in nanoseconds, with constructors for seconds, milliseconds and ISO 8601 strings, arithmetic, and a dedicated Time\TimeException.
$t = \Time\Duration::fromSeconds(2)->add(\Time\Duration::fromMilliseconds(500));
printf("%d.%09d seconds\n", $t->seconds, $t->nanoseconds);
var_dump($t > \Time\Duration::fromSeconds(2));
$d = \Time\Duration::fromIso8601DurationString("PT1H30M");
echo $d->seconds, "\n";
try { \Time\Duration::fromIso8601DurationString("nope"); } catch (\Time\TimeException $e) { echo get_class($e), ": ", $e->getMessage(), "\n"; }
2.500000000 seconds bool(true) 5400 Time\TimeException: The ISO 8601 duration string could not be parsed
Use it where a duration is passed around or compared, especially when seconds, milliseconds and ISO strings meet in one code path.
pack() and unpack() endianness
The format codes s S l L q Q f d now take < for little-endian and > for big-endian directly after the code. Before, the byte order depended on the machine or on a manual swap.
echo bin2hex(pack("l>", 1)), PHP_EOL, bin2hex(pack("l<", 1)), PHP_EOL, bin2hex(pack("f>", 1.5)), PHP_EOL;
var_dump(unpack("s>value", "\xff\xfe"));
var_dump(unpack("s<value", "\x01\x00"));
00000001 01000000 3fc00000 array(1) { ["value"]=> int(-2) } array(1) { ["value"]=> int(1) }
Use it for network protocols and file formats that fix a byte order, instead of swapping bytes after pack().
JSON error location
A JSON syntax error used to say only that the syntax was wrong. json_last_error_msg() and JsonException now carry the line and column, so a log line points at the broken character.
json_decode("{\"a\": 1, \"b\": }");
echo json_last_error_msg(), "\n";
try { json_decode("[1, 2,", flags: JSON_THROW_ON_ERROR); } catch (JsonException $e) { echo $e->getMessage(), "\n"; }
Syntax error near location 1:15 Syntax error near location 1:7
Use it when an API answer or a config file fails to parse: the message now tells the reader where to look.
Reflection additions
ReflectionProperty::isReadable() and isWritable() take a scope and an object, so a tool can ask whether a property is visible from a given class instead of reimplementing the visibility rules.
class A { public private(set) int $x = 1; public readonly int $y; public function __construct() { $this->y = 2; } }
$a = new A();
$x = new ReflectionProperty(A::class, "x");
var_dump($x->isReadable(null, $a), $x->isWritable(null, $a), $x->isWritable(A::class, $a));
$y = new ReflectionProperty(A::class, "y");
var_dump($y->isWritable(A::class, $a));
bool(true) bool(false) bool(true) bool(false)
The same release adds namespace helpers to ReflectionAttribute and ReflectionConstant and ReflectionParameter::getDocComment(). Use the visibility checks in serializers, ORMs and test helpers that set properties through reflection.
URI additions
The URI extension of PHP 8.5 learns to classify what it parsed: getUriType() and getHostType() on Uri\Rfc3986\Uri, and isSpecialScheme() plus getHostType() on Uri\WhatWg\Url.
$u = new Uri\Rfc3986\Uri("https://user@example.com:8080/a/b?q=1#top");
var_dump($u->getHost(), $u->getHostType(), $u->getUriType());
$w = Uri\WhatWg\Url::parse("https://example.com/");
var_dump($w->isSpecialScheme());
string(11) "example.com" enum(Uri\Rfc3986\UriHostType::RegisteredName) enum(Uri\Rfc3986\UriType::Uri) bool(true)
The release also adds UriBuilder, UrlBuilder and Uri\WhatWg\url_percent_encode(). Use the type checks in link validators and in code that treats a host name and an IP address differently.
WeakMap references
WeakMap accepted a reference only for an existing key. PHP 8.6 lets the first write create the key, which makes a counter that follows an object lifetime a one-liner.
$obj = new stdClass(); $map = new WeakMap(); $count = 0;
$map[$obj] = &$count; $count++;
var_dump($map[$obj]);
int(1)
Use it for per-object counters and caches that must disappear together with the object.
Smaller additions
The rest of the release is extension work. One line each, with the manual as the reference; no code here is invented.
| Area | What is new | Manual |
|---|---|---|
| Polling API | Io\Poll\Context, Watcher, Backend, Event, Handle and StreamPollHandle watch streams and sockets for readiness without a busy loop. | migration86 |
| Stream errors | StreamError, StreamException, the StreamErrorStore, StreamErrorMode and StreamErrorCode enums, stream_last_errors(), stream_clear_errors(), the context options error_mode, error_store and error_handler, and stream_socket_get_crypto_status(). | migration86 |
| Stream and socket context | New options: so_reuseaddr, so_keepalive, tcp_keepidle, tcp_keepintvl, tcp_keepcnt, so_linger, so_rcvbuf, so_sndbuf, filter.max_filter_count and the write_seek_mode filter parameter. | context options |
| Intl | IntlNumberRangeFormatter, grapheme_strrev(), Locale::getDisplayKeyword() and getDisplayKeywordValue(), the SpoofChecker bidi methods, and IntlDatePatternGenerator::getSkeleton() and getBaseSkeleton(). | Intl |
| Sodium | ipcrypt (twelve functions), sodium_bin2ip() and sodium_ip2bin(), SHAKE128 and SHAKE256, TurboSHAKE128 and TurboSHAKE256, X-Wing KEM and ML-KEM768 (libsodium 1.0.22 or newer). | Sodium |
| GMP | gmp_powm_sec() and gmp_prevprime(). | GMP |
| cURL | CURLINFO_SIZE_DELIVERED and CURLOPT_SEEKFUNCTION (libcurl 8.20 or newer). | cURL |
| OpenSSL streams | TLS session resumption, external PSK and TLS 1.3 early data (0-RTT). | OpenSSL |
| PDO_PGSQL | Pdo\Pgsql::ATTR_CHUNK_SIZE (libpq 17 or newer). | PDO_PGSQL |
| SNMP | AES192 and AES256, snmp_init_mib() and output options. | SNMP |
| SOAP | The keep_headers option. | SOAP |
| Phar | SplFileInfo overrides are honoured in buildFromDirectory() and in the iterator. | Phar |
Breaking changes
Four breaks hit ordinary code. The first is the coalescing operator: once __isset() has materialised a property, ?? and empty() read it and no longer call __get().
#[\AllowDynamicProperties]
class Example {
public function __isset(string $n): bool { $this->$n = "from __isset()"; return true; }
public function __get(string $n): string { return "from __get()"; }
}
var_dump((new Example)->foo ?? "default");
string(14) "from __isset()"
The second is trim(), rtrim() and ltrim(): the form feed \f is now in the default character list, next to the space, tab and newline.
var_dump(trim("\f hello \f"));
string(5) "hello"
The third is sessions: the INI defaults are now session.use_strict_mode=1, session.cookie_httponly=1 and session.cookie_samesite="Lax", and session_encode() returns an empty string for an empty session. Code that relied on the old permissive defaults must set them explicitly.
The fourth is unpack(): after a code, < and > are byte-order modifiers, so unpack("s<value", $bytes) returns the key value, where 8.5 returned the key <value. A format that used the character in a name needs a different name or an explicit repeat.
The rest are grouped, not listed one by one: new ValueErrors for bad array_filter() modes, array_change_key_case() cases, pathinfo() flags, scandir() sorting, NUL bytes in path and environment functions, and out-of-range number_format(), sleep() and usleep() arguments; notices for imprecise base_convert() and the binary and octal decoders; array_intersect() string conversion during the scan; foreach by reference after array compaction; DOM property visibility; preg_grep() returning false on a PCRE error; Phar auto-interpretation only for the .phar extension; SplFileObject iteration changes; tighter error types in GMP, GD, Intl, Zip, Zlib, SOAP, Sodium and URI; mbstring on Unicode 18; and TrueType files reported as font/ttf. The manual keeps the full list: backward incompatible changes in 8.6.
Deprecations
Deprecations do not break a page today; they mark code that PHP 9 will remove. The aliases and old helpers are the first group. This file triggers them on 8.6:
error_reporting(E_ALL);
set_error_handler(function ($n, $m) { echo "[$n] $m\n"; return true; });
var_dump(is_double(1.5), is_long(1), doubleval("2.5"));
define("FOO", 1, false);
echo metaphone("Thompson"), "\n";
echo spl_object_hash(new stdClass) !== "" ? "hash\n" : "";
class K { const namespace = 1; }
Deprecated: Declaring class constant called 'namespace' is deprecated in /e/deprecations.php on line 8 [8192] Function is_double() is deprecated since 8.6, use is_float() instead [8192] Function is_long() is deprecated since 8.6, use is_int() instead [8192] Function doubleval() is deprecated since 8.6, use floatval() instead bool(true) bool(true) float(2.5) [8192] define(): Argument #3 ($case_insensitive) is ignored and treated as false since declaration of case-insensitive constants is no longer supported, passing the argument explicitly is unnecessary [8192] Function metaphone() is deprecated since 8.6, use a userland phonetic matching library instead 0MPSN [8192] Function spl_object_hash() is deprecated since 8.6, consider using spl_object_id() instead hash
Two compile-time deprecations have no runtime output of their own: returning from a finally block, and returning a value from a constructor or destructor. The engine reports both when it compiles the file:
function f(): array { try { return [1]; } finally { return []; } }
var_dump(f());
function readonly() {}
class C { public function __construct() { return 1; } }
Deprecated: Returning from a finally block is deprecated in /e/deprecation_compile.php on line 2 Deprecated: Calling a function "readonly" is deprecated since 8.6 in /e/deprecation_compile.php on line 4 Deprecated: Returning a value from a constructor is deprecated in /e/deprecation_compile.php on line 5 array(0) { }
The rest of the list: ?array as the return type of __debugInfo(); let, is and _ as names; is_a() and is_subclass_of() with a string and allow_string=false; strcoll() and SORT_LOCALE_STRING; spl_classes(); the ArrayIterator sorting and flag methods; the SplFileObject CSV methods; objects passed to array_walk(), array_walk_recursive(), http_build_query() and mb_convert_variables() and the deflate_init() and inflate_init() option arrays (pass get_object_vars() instead); more than sixteen filters in one php://filter URL; every mb_ereg*, mb_split() and mb_regex_* function, which PHP 9 removes (use preg_* with /u); mysqli_get_charset() and mysqli_stmt_init(); Reflection setValue() and setRawValue() with a foreign object, and invoke() of a static method with an object; session save handlers without create_sid() or validateId(). Full list: deprecated features in 8.6.
Demo code in src
Our own pages already hold code that makes a good demo for each feature. The links point at the article, the line says what to look at.
- Closures and array_map, filter, reduce show one-argument callbacks such as fn($v) => strtoupper($v), the shape that partial application replaces.
- Readonly deep dive and Constructors and promotion show readonly properties written once in the constructor, the case that a default value now covers without a constructor argument.
- Attributes and the session demo handler show #[\Override] on methods; on constants it is new in 8.6.
- Enums deep dive and Enums hold backed enums with methods, where __debugInfo() now fits.
- Constructors and promotion shows class constants and default objects, the place where a mutable object constant can replace a static settings array.
- max() and min() document the two calls that clamp() replaces when they are nested.
- Date and Time in PHP and Compare two dates in PHP work with intervals in seconds, the unit Time\Duration models.
- pack() and unpack() build and read binary strings, where the new byte-order modifiers remove manual swaps.
- json_decode PHP parses JSON and reports errors, the page where the new location text appears.
- Reflection and attributes reads classes and properties through reflection, the code that gains isReadable() and isWritable().
- What is new in PHP 8.5 has the URI extension examples that the 8.6 type helpers extend.
- What is new in PHP 8.0 mentions WeakMap among the 8.0 additions, and spl_object_id() is the object identity helper that pairs with it.
Our code to update
This is a report, not an edit: no page below was changed for 8.6. Each hit says what the code does today and what it becomes on 8.6. None of it can land now, because the hosting runs 8.5; the change waits for the move to 8.6.
clamp(): no hits
A search for max(min(...)) and min(max(...)) in container/src/.php, container/src/dev/php and the PHP tools found no nested clamp. Nothing to change.
Partial application: 3 hits
dev/php/course/060_array_functions.php:71, before:
$upper = array_map(fn($v) => strtoupper($v), $names);
On 8.6:
$upper = array_map(strtoupper(?), $names);
dev/php/course/056_php85.php:71 and dev/php/versions/php85.php:81, before:
|> (fn($s) => str_replace(" ", "-", $s))
On 8.6:
|> str_replace(" ", "-", ?)
spl_object_hash(): 1 hit
dev/php/functions/spl_object_hash/index.php:89, before:
$id = spl_object_hash($object);
$storage[$id] = $object;
On 8.6:
$id = spl_object_id($object);
$storage[$id] = $object;
is_double(), is_long(), doubleval(): no hits
The three reference pages already use is_float(), is_int() and floatval() in their examples, so only the deprecated names in the prose remain, and the pages document the deprecation rather than call the aliases.
metaphone(): 2 calls in 1 file
dev/php/functions/metaphone/index.php:90 and :91, before:
var_dump(metaphone("programming"));
var_dump(metaphone("programmer"));
There is no drop-in core replacement: the 8.6 version of these lines is the same code plus an E_DEPRECATED notice, and the manual sends a project to a userland phonetic library. The page can stay as documentation of the deprecated function until PHP 9 removes it.
define() third argument: 1 hit
dev/php/functions/define/index.php:88, before:
define("GREETING", "Hello you.", true);
On 8.6:
define("GREETING", "Hello you.");
mbregex: no hits
The mb_ereg*, mb_split() and mb_regex_* pages document the functions but ship no runnable call, so there is no call site to move to preg_* with /u.
Objects to array_walk() and http_build_query(): no hits
Every array_walk() and array_walk_recursive() example passes an array, and DictPage.php:487 passes the local $q array to http_build_query(). No object is passed, so no get_object_vars() is needed.
return in finally: no hits
The exception lessons explain finally but never return from it. Nothing to change.
__debugInfo() with ?array: no hits
No page defines __debugInfo() at all, so the ?array deprecation has no target.
Readonly property from a constant: no hits
The readonly lessons write readonly properties from constructor arguments, not from a constant, so no property can move its value into a default declaration.
Hand-written timeouts: 5 hits
dev/php/course/089_curl.php:72, before:
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
On 8.6:
$timeout = \Time\Duration::fromSeconds(10);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout->seconds);
dev/php/rest/demo/get_1.php:49 and dev/php/rest/demo/post_1.php:60, before:
CURLOPT_TIMEOUT => 30,
On 8.6:
CURLOPT_TIMEOUT => \Time\Duration::fromSeconds(30)->seconds,
dev/php/symfony/course/41_http_client.php:113, before:
"timeout" => 5.0,
On 8.6:
"timeout" => \Time\Duration::fromMilliseconds(5000)->seconds,
dev/php/functions/stream_set_timeout/index.php:97, before:
stream_set_timeout($fp, 2);
On 8.6:
$timeout = \Time\Duration::fromSeconds(2);
stream_set_timeout($fp, $timeout->seconds, $timeout->nanoseconds / 1000);
Released 19 November 2026. Read the other end of the timeline: what is new in PHP 8.5 and what is new in PHP 8.0 vs PHP 7.
Article author: Arthur Isaev