•5 min read

PHP 8.6 Upgrade: Three Session Defaults Flipped, One Does Nothing

Every PHP upgrade that has cost me a night had the same shape. No stack trace, no 500 page, just a login that quietly stopped keeping people logged in, or a payment provider that sent the customer back and found a stranger.

PHP 8.6.0 ships tomorrow, November 19, and it has one of those inside it. It is not in the release highlights. It is three lines in ext/session/session.c.

A railway switch machine between two numbered tracks, with a red signal lamp lit beside the rails

The defaults moved and your config did not

The headline for 8.6 is partial application. I will get to that. What pages someone at 2am is three session defaults that moved in the engine itself:

STD_PHP_INI_BOOLEAN("session.cookie_httponly", "1", ...)
STD_PHP_INI_ENTRY("session.cookie_samesite",   "Lax", ...)
STD_PHP_INI_BOOLEAN("session.use_strict_mode", "1", ...)

In 8.5 those read "0", "" and "0". This is not a feature you switch on. It is what your app starts doing the moment the binary changes underneath it, with no diff in your repo and nothing to review.

Check before you swap, on every box, because FPM pool settings override php.ini and that is usually where this gets decided:

php -i | grep '^session\.' | grep -E 'strict_mode|httponly|samesite'

On the 8.0.30 build I keep around for this kind of question, that prints 0, no value, no value. Anything showing 1, 1, Lax afterwards came from the new binary, not from you. The manual's configuration page still listed the old values when I looked, so ask the machine rather than a table.

Strict mode only works if your handler can answer

Here is the bit I have not seen in any of the 8.6 write-ups. Strict mode rejects a session ID the storage layer has never seen. The engine can only ask that if your save handler exposes validateId():

} else if (PS(use_strict_mode) && PS(mod)->s_validate_sid &&
    PS(mod)->s_validate_sid(&PS(mod_data), PS(id)) == FAILURE
) {

No s_validate_sid, no branch. The ID from the cookie is adopted, same as before. So if you registered your own Redis or Memcached handler that implements SessionHandlerInterface and nothing else, strict mode has been decoration for years and switching it on by default changes nothing. The directive reads 1 while your app keeps trusting whatever ID the client hands it.

8.6 makes this loud in two directions. First, SessionHandler::validateId() is new, so wrapping an internal handler with SessionHandler now validates where it could not before. Sessions that were never rejected can start coming back with fresh IDs, which users experience as random logouts. Second, and this one hits your log first, declaring a class that implements SessionHandlerInterface without defining both create_sid() and validateId() now prints a warning for each missing method:

Class Foo implementing SessionHandlerInterface is missing the validateId() method which will be required in PHP 9.0

It fires when the class is linked, not when a session starts, so you will see it on requests that never touch $_SESSION. If display_errors is on anywhere near production, it ends up in the HTML.

SameSite=Lax and the callback that POSTs

Lax sends the session cookie on top-level navigations using safe methods. A GET callback works fine. A cross-site POST does not, and that covers a whole family of flows: payment returns, older SSO endpoints, a form posted from inside a third-party iframe. The browser withholds the cookie, PHP starts an empty session, and your app concludes the visitor is a guest.

Your test suite will not catch this, because nothing in it is cross-site. Load the flow in a real browser with the network panel open and watch for the missing cookie.

If a flow needs it back, be precise: session.cookie_samesite=None plus session.cookie_secure=1, on the routes that need it. Loosening the whole application to None to rescue one callback trades a login bug for a CSRF one.

Laravel people get a slightly different deal. config/session.php already sets http_only and same_site, so those two flips land on values you wrote yourself. session.use_strict_mode is not in that file because it is an engine directive, so it is the one that changes without the framework noticing.

The parts of 8.6 I will actually use

Partial application removes a category of pointless arrow functions. ? fills one argument position, ... fills whatever is left, and you get a Closure back:

$slugify = str_replace(' ', '-', ?);
echo $slugify('Hello World');  // Hello-World

$titles = array_map(strtolower(?), $titles);

Arguments you do supply are evaluated when the partial is built, not when it is called, so do not park getenv() in there and expect it to be read later.

clamp() is the helper everyone has written by hand. This one throws ValueError when min exceeds max instead of returning something weird, and it hands back the original type unconverted, so keep your numerics numeric.

Readonly properties can take a default now, retiring constructors that existed only to assign a constant. One small thing with teeth: trim(), rtrim() and ltrim() now strip a form feed by default, so anything parsing fixed-width or imported text should spell out its character list.

What I would do on the 18th

Diff php -i between the two binaries on one machine. Grep for session_set_save_handler and check whether those classes define validateId(). Then walk a cross-site callback through a browser by hand.

Half an hour, and it covers the only two ways this release can hurt you quietly.

The rest of 8.6 is a fine release. It is just funny that the thing deserving the most attention is a default rather than a feature, and that the default only works if a handler you wrote years ago cooperates. The checklist lives in Snippet Ark for the next upgrade window. If session handling has bitten you before, the Sanctum stateful domains mess is the same bug in a different hat.