PHP 8.6: Safer Sessions, Partial Functions

November 22, 2026 · 6 min read · By Nadia Kowalski

PHP 8.6 was released on November 19, 2026, as a major update of the PHP language. Three changes matter most for teams deciding whether to upgrade now: partial function application, secure-by-default session settings, and a set of engine-level performance optimizations.

What Partial Function Application Changes

Partial function application (PFA) lets you bind some arguments of a call up front and leave the rest as placeholders. The result is a closure you can invoke later with the remaining arguments, without writing an anonymous function by hand. You mark the arguments you want to supply at call time with the ? placeholder. The feature comes from the partial_function_application_v2 RFC.

<?php
$pad = str_pad(?, 12, '.');
echo $pad('PHP 8.6'); // "PHP 8.6....."
?>

PFA is not the same as a first-class callable. With PFA you still name the concrete function and supply real values; the engine hands back a new callable that remembers them. The practical effect is shorter call sites and a callable whose real target the engine, static analysis, and the JIT can still see, unlike a closure that hides the call behind a body of userland code.

For teams already using use() closures to capture configuration, PFA often replaces them with a single line and removes a layer of indirection. The main thing to watch is readability: a placeholder list is compact, but a call with several ? markers is only clearer if the remaining arguments are supplied in the same order at the call site.

clamp(), Duration, and the Polling API

Three smaller additions round out the release. None of them change existing behavior, but each replaces a pattern you probably maintain by hand today.

clamp() constrains a value to a range: it returns the given value if it is within range, otherwise the nearest bound. It replaces the usual nested max($min, min($max, $value)) with a single, readable call.

<?php
echo clamp(15, 0, 10);  // 10
echo clamp(5, 0, 10);   // 5
echo clamp(-3, 0, 10);  // 0
?>

The Date extension adds a new Time\Duration class, a dedicated type for representing a duration of time instead of reusing interval or timestamp primitives. A dedicated duration type keeps arithmetic and formatting intent explicit, which helps when durations and absolute timestamps are easy to confuse in review. The UPGRADING notes record that the class was added; check the class itself for the exact surface before you depend on it.

The IO extension gains a new polling API. The classes involved are Io\Poll\Context, Io\Poll\Watcher, Io\Poll\Backend, Io\Poll\Event, and Io\Poll\Handle. This gives event-loop style code a first-party way to wait on multiple handles. Treat the API as new: verify the method signatures against the source rather than assuming they mirror a third-party loop, and budget time to test behavior on your target build before adopting it.

Session Defaults Are Now Secure by Default

Three session INI defaults changed, and each closes a common, exploitable gap. If your application relies on the previous behavior, you must opt out explicitly.

Setting New default What it means
session.use_strict_mode 1 (was 0) Strict mode rejects uninitialized session IDs, mitigating session fixation.
session.cookie_httponly 1 (was 0) Session cookies are no longer readable from JavaScript via document.cookie.
session.cookie_samesite "Lax" (was unset) Session cookies are no longer sent on cross-site requests other than top-level navigations using safe HTTP methods.

Three groups must change configuration to keep old behavior:

  • Custom session handlers that relied on accepting externally supplied IDs without a matching storage entry must implement validateId() / create_sid(), or explicitly set session.use_strict_mode to 0.
  • Applications that read the session cookie from JavaScript must explicitly set session.cookie_httponly to 0.
  • Applications that depend on session cookies being sent on cross-site POST submissions must explicitly set session.cookie_samesite to "None" and also set session.cookie_secure to 1.

The pattern across all three defaults is the same: the safe choice is now the default, and the unsafe choice requires a deliberate override. That shifts the burden onto the small number of applications with a legitimate reason to weaken the setting, instead of onto everyone else. When you override any of these values, record the reason next to the configuration so a future audit does not silently re-tighten it.

<?php
// Legacy app that must receive session cookies on cross-site POST:
ini_set('session.cookie_samesite', 'None');
ini_set('session.cookie_secure', '1');
session_start();
?>

Performance Wins You Can Measure

The performance work in 8.6 is about removing overhead the engine used to pay on common calls, not about new primitives. Several changes are worth knowing:

  • printf() calls that use only "%s" and "%d" are compiled into the equivalent string interpolation, avoiding the function-call overhead and repeated parsing of the format string.
  • array_map() with a first-class callable or a partial function application callback is compiled into the equivalent foreach loop, avoiding intermediate Closure objects and the cost of calling userland callbacks from internal functions, while giving the JIT better insight.
  • A stateless closure cache was added.
  • JSON encoding of arrays and objects is faster, and indentation generation in json_encode() with JSON_PRETTY_PRINT was improved.
  • Standard-library work also speeds up array_map() when multiple arrays are passed, and array_sum() / array_product() for integer-only arrays.
<?php
$names = ['alice', 'bob', 'carol'];
$loud   = array_map(strtoupper(...), $names);      // first-class callable
$padded = array_map(str_pad(?, 8, '.'), $names);   // partial function application
?>

These rewrites matter most in tight loops and hot request paths where a cheap call is repeated thousands of times. Because the gains are compilation and caching changes rather than new syntax, you do not need to rewrite code to benefit, but you do need a realistic profile to know whether the change is visible in your application at all.

One caution on evidence: the UPGRADING file gives no benchmark numbers. It describes what the engine now compiles or caches; it does not publish speedups. Treat any headline percentage you see elsewhere as unverified and measure against your own workload before you cite a gain. If you publish upgrade notes internally, link to the UPGRADING file and label any speed claims as specific to your benchmark, not to PHP generally.

Breaking Changes to Test Before You Upgrade

These are behavior changes, not deprecations. Run your suite against 8.6 and read the UPGRADING file in full; the table below covers the ones most likely to surface in real code.

Change What to check
By-reference foreach and array compaction Loops may now visit previously skipped elements after compaction; internal pointers on deleted elements move to the next surviving element during copy-on-write.
?? / empty() on magic properties No longer call __get() when __isset() has materialized the property by writing into the property table; the freshly written value is returned directly. isset() is unaffected.
preg_grep() Returns false instead of a partial array when a PCRE execution error occurs.
session_encode() Returns an empty string instead of false for empty sessions; it returns false only when the data could not be encoded.
ftp_nb_* functions ftp_nb_fget(), ftp_nb_fput(), ftp_nb_get(), and ftp_nb_put() throw an Error when the connection is already transferring, instead of warning and returning false.
DOM readonly properties DOM properties previously documented as @readonly are now declared with asymmetric visibility (public private(set)).

A few additive changes are worth testing even though they are not breakages: readonly properties may now declare default values, #[Override] can be applied to class constants including enum cases, and objects stored in constants or class constants can be mutated directly via OBJ->prop = $val. Confirm that static analysis and code style rules understand these forms before adopting them.

Upgrade checklist:

  1. Run the full test suite on 8.6 with deprecations and warnings enabled.
  2. Audit session configuration against the new strict-mode, HttpOnly, and SameSite defaults; document every explicit override.
  3. Review code that pairs __isset() with __get() on magic properties.
  4. Search for assumptions about @readonly visibility and adjust reflection or extension code.
  5. Check error handling around preg_grep() and session_encode() return values.
  6. Wrap ftp_nb_* calls that can now throw instead of returning false.
  7. Decide whether to enable error_include_args (new, off by default) if you rely on consistent argument display in errors.
  8. Benchmark the hot paths above on your own traffic rather than trusting published numbers.

Related Reading

Sources and References

Nadia Kowalski

Has read every privacy policy you've ever skipped. Fluent in GDPR, CCPA, SOC 2, and several other acronyms that make people's eyes glaze over. Processes regulatory updates faster than most organizations can schedule a meeting about them. Her idea of light reading is a 200-page compliance framework, and she remembers all of it.