---
title: 'PHP 8.6: Partial Application, Duration, clamp & Migration | DevSense'
description: 'An overview of PHP 8.6 (released 19 November 2026): partial function application with the ? placeholder, the Time\Duration class, the clamp() function, the SortDirection enum, readonly properties with default values, #[\Override] for constants, secure session defaults, deprecations and backward-incompatible changes.'
faq:
    - { question: 'What is partial function application in PHP 8.6?', answer: "It's a way to create a new closure from an existing function by fixing some arguments and leaving the rest for later. A `?` placeholder marks a missing argument, and `...` stands for all the remaining arguments. Values passed up front are evaluated the moment the closure is created." }
    - { question: 'Why do you need the Time\Duration class?', answer: 'Time\Duration is an immutable object for working with time intervals at nanosecond precision. It has factories like Duration::fromMilliseconds() and the methods add() and multiplyBy(), and instances can be compared with the < and > operators. It gets rid of the magic numbers in seconds and microseconds you''d otherwise scatter through timeout, delay and backoff code.' }
    - { question: 'What does the clamp() function do in PHP 8.6?', answer: 'clamp(value, min, max) returns the value constrained to the range [min, max]: below min it returns min, above max it returns max. It works with any comparable values, not just numbers. If min is greater than max, it throws a ValueError.' }
    - { question: 'Which PHP 8.6 changes will break old code?', answer: 'The main ones: trim() now strips the form-feed character (\f) by default; fclose(), file_put_contents() and copy() return false on a buffer-flush error; several functions throw ValueError on invalid arguments; and the default session settings have been tightened. Plus deprecations of is_long()/is_double(), spl_object_hash(), return inside finally, and the mbstring regex functions.' }
published: '2026-11-24'
---
# PHP 8.6: Key New Features and Interactive Guide

Exactly a year after PHP 8.5, PHP 8.6 arrives — released on **19 November 2026**. And while 8.5 will be remembered for the pipe operator, 8.6 is a release about **ergonomics and strictness**: the language learns to assemble functions from pieces, gains an honest type for time intervals, the long-overdue `clamp()`, and quietly but decisively tightens the security screws in places that used to be insecure by default.

Let's walk through the key features with live examples, go over what breaks on upgrade, and finish with a self-check quiz.

---

## Table of Contents
* [Partial function application (`?` and `...`)](#partial-application)
* [The `Time\Duration` class](#duration)
* [The `clamp()` function](#clamp)
* [The `SortDirection` enum](#sort-direction)
* [`readonly` properties with default values](#readonly-defaults)
* [Small niceties worth having](#niceties)
* [Secure session defaults](#session-security)
* [Backward-incompatible changes and deprecations](#backward-incompatible)
* [🧠 Self-Check Questions](#self-check)

---

<a id="partial-application"></a>
## Partial function application (`?` and `...`)

The headline feature of the release. You can now turn any function into a new closure, fixing some arguments and leaving the rest for later. A **`?`** placeholder marks a missing argument, and **`...`** stands for all the remaining arguments.

```php
// Before: spinning up a wrapper closure just for one operation
$toSlug = fn (string $s) => str_replace(' ', '-', $s);

// After: fix the first two arguments of str_replace, wait for the third
$toSlug = str_replace(' ', '-', ?);

$toSlug('Hello World'); // 'Hello-World'
```

The key subtlety: arguments passed at creation time are **evaluated immediately**, while each `?` becomes a required parameter of the new closure, preserving the types and default values of the original function. That makes partial application a perfect partner for the pipe operator from 8.5 and for methods like `array_map`:

```php
$titles = array_map(trim(...), $rawTitles);          // first-class callable
$shift  = array_map(str_pad(?, 10, '0', STR_PAD_LEFT), $codes); // partial application
```

> [!NOTE]
> Don't confuse `trim(...)` (the first-class callable syntax from PHP 8.1, "the whole function as a closure") with `str_replace(' ', '-', ?)` (partial application, "fix this, I'll wait for the rest"). In 8.6 the two complement each other beautifully.

---

<a id="duration"></a>
## The `Time\Duration` class

PHP finally gets a proper type for a time interval — the immutable **`Time\Duration`** class, with nanosecond precision and a range of more than 250 years. No more guessing whether your timeout is in seconds, milliseconds or microseconds.

```php
use Time\Duration;

$base = Duration::fromMilliseconds(100);

// Exponential backoff without magic numbers
$delay = $base->multiplyBy(2 ** $attempt);

if ($delay > Duration::fromSeconds(30)) {
    $delay = Duration::fromSeconds(30);
}

time_nanosleep($delay->seconds, $delay->nanoseconds);
```

The factories `Duration::fromSeconds()`, `fromMilliseconds()`, `fromMinutes()`, the `add()` and `multiplyBy()` methods, the `->seconds` and `->nanoseconds` properties — and instances can be compared directly with the `<` and `>` operators. This is exactly the type that was missing from the code on [resilient external integrations](../architecture/resilient-external-integrations) and [queues](../architecture/laravel-queues-production): backoff and timeouts stop being nameless numbers.

---

<a id="clamp"></a>
## The `clamp()` function

A tiny function everyone hand-rolled in every project is finally in the core:

```php
// Before
$percent = max(0, min(100, $raw));

// After
$percent = clamp($raw, 0, 100);

var_dump(clamp(110, 0, 100)); // int(100)
var_dump(clamp(-5,  0, 100)); // int(0)
```

`clamp(value, min, max)` returns the value constrained to the range. It works not only with numbers but with any comparable values — for example, those same `Time\Duration` objects. If `min` is greater than `max`, it throws a `ValueError`. Named arguments are supported too: `clamp($raw, min: 0, max: 100)`.

---

<a id="sort-direction"></a>
## The `SortDirection` enum

Instead of memorizing the difference between `SORT_ASC`, `SORT_REGULAR` and `SORT_STRING`, sort direction is now expressed with a type-safe enum with two cases — `SortDirection::Ascending` and `SortDirection::Descending`. Wherever an API expects a direction, passing an old string constant like `SORT_STRING` will now raise a `TypeError` — the error gets caught during development rather than in production.

---

<a id="readonly-defaults"></a>
## `readonly` properties with default values

Before 8.6, trying to give a `readonly` property a default value was a compile error. Now it's allowed:

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

The default value counts as initialization, so the constructor can no longer overwrite it — otherwise the `readonly` semantics are unchanged. A small thing that removes unnecessary noise from DTOs and configuration objects (covered in detail in the article on [Action classes, services and DTOs](../architecture/laravel-actions-services-dto)).

---

<a id="niceties"></a>
## Small niceties worth having

* **`#[\Override]` for constants and enum cases.** The attribute from 8.3 now works beyond methods: tag a class constant with it, and if it doesn't override a parent one, you get a fatal error. Typos in constant names no longer slip through silently.
* **Doc comments for parameters.** A `/** ... */` comment before a function parameter is now available through `ReflectionParameter::getDocComment()` — handy for documentation generators and validators.
* **Writing to objects stored in constants.** `Config::DEFAULTS->timeout = 30` is no longer an error (writing to an array through a constant is still forbidden).
* **Clearer JSON error messages.** `json_last_error_msg()` and `JsonException` now point to the location of the error — not just "Syntax error", but with coordinates.
* **`grapheme_strrev()`** reverses a string by grapheme clusters, without breaking emoji and composite characters.
* **Faster under the hood.** `array_map()` with a first-class or partially applied callback compiles to a loop with no intermediate closure; `printf()` and `json_encode()` got faster; stateless closures are cached and reused.

---

<a id="session-security"></a>
## Secure session defaults

One change deserves a special mention, because it quietly fixes a whole class of common vulnerabilities. PHP 8.6 switches the session defaults to secure values:

| Directive | Before | After |
|-----------|------|-------|
| `session.use_strict_mode` | `0` | `1` |
| `session.cookie_httponly` | `0` | `1` |
| `session.cookie_samesite` | unset | `Lax` |

Strict mode protects against session fixation, `httponly` hides the cookie from JavaScript (and therefore from theft via XSS), and `SameSite=Lax` lowers the risk of CSRF. If you set these values explicitly (as you should), nothing changes. If you relied on the defaults, they're now on your side. This topic sits nicely alongside the breakdown of [web attacks and how to prevent them](../architecture/web-attacks-and-prevention).

---

<a id="backward-incompatible"></a>
## Backward-incompatible changes and deprecations

Upgrading to 8.6 is usually smooth, but a few things are worth checking in advance.

**What might break:**

* **`trim()`, `ltrim()` and `rtrim()` now strip the form-feed character `\f` by default.** If you relied on `\f` being left in place, specify the character list explicitly as the second argument.
* **`fclose()`, `file_put_contents()` and `copy()` return `false` if flushing or closing the stream fails.** Previously such an error could get lost — check the result.
* **More `ValueError` instead of a silent `false`** from a number of functions (`getenv()`, `putenv()`, `setlocale()`, `parse_str()` and others) on invalid arguments or strings containing a NUL byte.
* **Secure session defaults** from the section above — the default behavior has changed.

**Main deprecations** (still working, but start preparing to move away):

* `is_long()`, `is_integer()`, `is_double()`, `doubleval()` → use `is_int()`, `is_float()`, `floatval()`.
* `spl_object_hash()` → `spl_object_id()`.
* `return` inside a `finally` block — the behavior is too unintuitive.
* Returning a value from `__construct()` or `__destruct()`.
* The mbstring regex functions (`mb_ereg()`, `mb_split()` and the rest) — the Oniguruma engine isn't supported; switch to PCRE with the `u` modifier.
* `strcoll()` and the `SORT_LOCALE_STRING` flag → the `Collator` class from intl.
* The third argument of `define()` (case-insensitive constants).

The full list is in the official `UPGRADING`; check it against your code before production, and roll out using the [zero-downtime scheme](../architecture/zero-downtime-deployment-laravel).

---

<a id="self-check"></a>
## 🧠 Self-Check Questions

Let's test your knowledge of PHP 8.6:

1. How does the `?` placeholder in partial application differ from the `trim(...)` syntax?
2. **True or false?** `clamp(5, 10, 0)` simply returns `5`, because the value is already within the "corridor".
3. What type does `Duration::fromMilliseconds(250)` return, and which two of its properties conveniently supply the arguments for `time_nanosleep()`?
4. Which three session directives did PHP 8.6 switch to secure defaults?
5. What do you replace the deprecated `is_long()` and `spl_object_hash()` with?

<details>
<summary><b>Reveal Answers</b></summary>

1. `trim(...)` is a **first-class callable**: the entire function is turned into a closure, with no argument fixed. `str_replace(' ', '-', ?)` is **partial application**: some arguments are fixed up front, while `?` marks the ones the closure will accept when called.
2. **False.** If `min` (10) is greater than `max` (0), `clamp()` throws a `ValueError` rather than returning the value.
3. It returns an immutable `Time\Duration` object. For `time_nanosleep()`, the `->seconds` and `->nanoseconds` properties come in handy.
4. `session.use_strict_mode` (to `1`), `session.cookie_httponly` (to `1`) and `session.cookie_samesite` (to `Lax`).
5. `is_long()` → `is_int()`; `spl_object_hash()` → `spl_object_id()`.
</details>