# PHP 8.6 upgrade: new features and the breaking changes to check

> PHP 8.6 was released on 19 November 2026 with partial function application, a Duration class, the Io\Poll API, clamp() and a SortDirection enum. The upgrade risks are in the details, notably stricter session cookie defaults, new ValueErrors, form feeds stripped by trim() and a batch of deprecations.

Published 2026-11-19 by the CodeBeast Team · https://codebeast.ai/blog/php-8-6-upgrade-breaking-changes

[PHP 8.6 was released](https://www.php.net/releases/8.6/en.php) on 19 November 2026. The headline features are partial function application, a `\Time\Duration` class, a new `Io\Poll` API and a `clamp()` function. For most teams the more urgent part is the [backward-incompatible changes list](https://www.php.net/manual/en/migration86.incompatible.php): session cookies are stricter by default, many functions now throw instead of silently truncating, and `trim()` strips one more character. This post covers what's new and what to test first.

## The new features worth knowing

### Partial function application

You can now supply some of a function's arguments in advance, using `?` and `...` as placeholders. The result is a `Closure`, and the function only runs when the remaining arguments are passed. The release page's example:

```php
$versions = ['8.4', '8.5', '8.6', '8.7', '9.0'];

$supportsPfa = array_filter(
    $versions,
    version_compare(?, '8.6', '>='),
);
```

This replaces a lot of one-line `fn ($v) => version_compare($v, '8.6', '>=')` closures in callback-heavy code.

### Duration, Io\Poll, clamp and SortDirection

- **`\Time\Duration`** represents elapsed time "as measured by a stopwatch", with constructors such as `Duration::fromSeconds()` and `Duration::fromMilliseconds()`. Useful for timeouts and retry backoff, where bare integers invite unit mistakes.
- **`Io\Poll`** monitors many streams at once using the best mechanism on each platform (epoll, kqueue, event ports or WSAPoll), without the scalability limits of `stream_select()`. This matters for long-running workers and async libraries.
- **`clamp()`** keeps a value inside a range: `clamp(-10, 0, 100)` returns `int(0)`.
- **`SortDirection`** is an enum with `Ascending` and `Descending` cases, giving libraries a type-safe sort-order parameter instead of overloaded integer constants.

### Readonly property defaults

Instance readonly properties, including those in readonly classes, can now declare a default value:

```php
final readonly class SlugRule implements Rule
{
    public string $parser = SlugParser::class;
}
```

## Breaking changes to test first

The full list is long. These are the ones most likely to surface in a typical web application.

### Session defaults are stricter

Three session INI defaults changed:

| Setting | Before | PHP 8.6 |
|---|---|---|
| `session.use_strict_mode` | `0` | `1` |
| `session.cookie_httponly` | `0` | `1` |
| `session.cookie_samesite` | unset | `"Lax"` |

These are better defaults, but each can break something. Custom session handlers that accept externally supplied IDs must now implement `validateId()` and `create_sid()`, or set strict mode back to `0`. JavaScript that reads the session cookie will stop working. Flows that rely on a cross-site POST carrying the session, such as some payment or SSO callbacks, need `session.cookie_samesite = "None"` together with `session.cookie_secure = 1`.

If you set these explicitly in `php.ini` or with `ini_set()`, nothing changes for you. Check what you rely on implicitly:

```bash
php -i | grep -E 'session\.(use_strict_mode|cookie_httponly|cookie_samesite)'
```

There are two smaller session changes too. `session_encode()` now returns `""` instead of `false` for an empty session. With `session.lazy_write` on and a handler implementing `SessionUpdateTimestampHandlerInterface`, empty sessions now call `updateTimestamp()` instead of `write()`, so handlers that destroyed sessions in `write()` need that logic moved.

### Throwing instead of silently truncating

Many functions now raise a `ValueError` for out-of-range values, invalid flags or strings containing NUL bytes. Examples include `getenv()`, `putenv()`, `parse_str()`, `setlocale()`, the `file_exists()`/`is_file()`/`stat()` family, `number_format()` with an out-of-range `decimals`, and `sleep()` above `UINT_MAX`. Code that passes user input straight into filesystem checks without validating it will now throw where it used to return `false`.

### Other changes that change results

- `trim()`, `ltrim()` and `rtrim()` now strip form feed (`\f`) by default. `trim("\f hello \f")` returns `"hello"`.
- `fclose()`, `file_put_contents()` and `copy()` return `false` when flushing or closing the stream fails, instead of ignoring the failure.
- `preg_grep()` returns `false` instead of a partial array on a PCRE execution error, such as malformed UTF-8 with the `u` modifier.
- In `unpack()`, `<` or `>` right after a format code is now an endianness modifier: `'s<value'` yields a key named `value`, not `<value`.
- With PDO_PGSQL persistent connections, session state such as `SET` values and temporary tables is reset when the last PDO object using the connection is destroyed.
- Fileinfo reports TrueType fonts as `font/ttf` instead of `font/sfnt`, which can affect upload allow-lists.
- `??` and `empty()` on a magic property no longer call `__get()` when `__isset()` has written the property.

## Deprecations to clean up

Deprecations don't break anything yet, but they fill logs and will become errors later:

- `return` inside a `finally` block.
- Returning a value from `__construct()` or `__destruct()`, or making them generators.
- The mbstring regex functions such as `mb_ereg()` and `mb_split()`, because the Oniguruma library they use is no longer maintained.
- The `is_double()`, `is_long()`, `is_integer()` and `doubleval()` aliases. Use `is_float()`, `is_int()` and `floatval()`.
- `spl_object_hash()` in favour of `spl_object_id()`, and `spl_classes()` in favour of `ReflectionExtension::getClassNames()`.

The alias deprecations are mechanical find-and-replace work. The `mb_ereg()` family needs real rewrites to `preg_*` functions, so find those early.

## A practical upgrade plan

1. **Check your dependencies.** `composer why-not php 8.6.0` lists packages whose constraints block the upgrade.
2. **Add PHP 8.6 to CI** alongside your current version, with deprecations visible (`error_reporting=E_ALL`) so the new notices show up in test output.
3. **Pin session settings explicitly** in your config, whichever values you choose, so behaviour doesn't depend on the PHP version.
4. **Grep for the risky calls**: `mb_ereg`, `mb_split`, `is_double`, `is_long`, `is_integer`, `doubleval`, `spl_object_hash`, `unpack(`, and `finally` blocks containing `return`.
5. **Test sign-in and cross-site flows in a browser**, not just unit tests. Cookie attribute changes only show up when a real browser enforces them.

That last step is where agent-driven upgrades often fall short: the diff looks fine and the unit tests pass, but a login callback breaks. CodeBeast's [Test agent](/docs/review-and-test) boots the app and works through the flows named in the plan in a real browser, which is the kind of check SameSite changes need.

## Sources

- [PHP 8.6 release announcement](https://www.php.net/releases/8.6/en.php)
- [PHP 8.6 migration guide](https://www.php.net/manual/en/migration86.php)
- [PHP 8.6 backward-incompatible changes](https://www.php.net/manual/en/migration86.incompatible.php)

## FAQ

### When was PHP 8.6 released?

PHP 8.6 was released on 19 November 2026. It is a minor version, which the PHP manual says brings new features and "a few incompatibilities that should be tested for before switching PHP versions in production environments."

### What is partial function application in PHP 8.6?

It lets you call a function with some arguments filled in and `?` or `...` placeholders for the rest. Instead of running, the call returns a `Closure` that takes the missing arguments. It is a shorter alternative to wrapping a call in an arrow function.

### Will PHP 8.6 break my sessions?

It might. `session.use_strict_mode` and `session.cookie_httponly` now default to on, and `session.cookie_samesite` defaults to `Lax`. Custom session handlers, JavaScript that reads the session cookie and cross-site POST flows are the usual places this shows up.

### Is mb_ereg deprecated in PHP 8.6?

Yes. The mbstring regular expression functions, including `mb_ereg()` and `mb_split()`, are deprecated because the underlying Oniguruma library is no longer maintained. Plan to move that code to the `preg_*` functions.
