Talk to us

Blog · 21 November 2026 · Rob Sherwood

PHP 8.6 Is Out, and It Changes How Sessions Behave

PHP 8.6 came out on Thursday 19 November. Most of the coverage is about the new toys, and there are some nice ones. The bit I'd pay attention to if you run a PHP app is quieter: PHP has changed how sessions behave out of the box, and a few everyday functions have got stricter about failure.

None of it is bad. Most of it is PHP doing by default what careful developers have set by hand for years. But "by default" is where older apps get caught out, so it's worth ten minutes before anyone types apt upgrade.

What changed with sessions

Three settings in the session extension have new defaults. They were voted through in an accepted RFC, each one unopposed:

  • session.use_strict_mode goes from 0 to 1. PHP will no longer accept a session ID it didn't create itself. That closes off session fixation, where an attacker hands someone a session ID they already know.
  • session.cookie_httponly goes from 0 to 1. JavaScript can no longer read the session cookie through document.cookie, which takes a lot of the sting out of a cross-site scripting bug.
  • session.cookie_samesite goes from empty to Lax. The browser still sends the session cookie on normal same-site requests and when someone clicks a link to your site, but not on cross-site POSTs or cross-site requests for embedded content.

All three are sensible. The catch is apps that were quietly relying on the old behaviour.

What might break

The RFC is refreshingly honest about this. The short version:

  • Cross-site POSTs back into a logged-in session. With SameSite set to Lax, a form on another site that posts to yours arrives without the session cookie. The RFC names service provider initiated SAML single sign-on and legacy cross-origin form submissions as the cases it expects to hit. Anything else where an outside service posts the user's browser back to your site and you expect them to still be logged in deserves a test too.
  • Your app embedded in someone else's site. If your app runs inside an iframe on another domain and needs a session, that's a cross-site sub-request, and the cookie won't go with it under Lax.
  • Hand-made session IDs. Some older apps pass a session ID between subdomains or systems and start a session with it. Strict mode rejects IDs PHP didn't issue, so with the built-in files handler that trick stops working.
  • Custom session handlers. The release notes deprecate custom handlers that don't implement both create_sid() and validateId(). It's a deprecation rather than a break, but if your app stores sessions in its own database table, it's one to put on the list.

For the cross-site cases, the RFC's suggestion is to set SameSite=None with Secure on the specific endpoints that need it, or move to a token-based flow. That's a deliberate decision for a handful of routes, rather than switching protection off for the whole app.

The other side: you might not get the new defaults at all

These are defaults. If your php.ini, your framework or your own code sets any of these values explicitly, the explicit setting wins. Plenty of servers carry an old php.ini forward through every upgrade, so you could install PHP 8.6 and find nothing has changed.

Worth knowing which way round you are. Run php -i | grep session on the server (and check from a web request too, because the command line and PHP-FPM often read different ini files). If you see use_strict_mode still at 0, decide whether that's on purpose.

The quieter changes to functions

Away from sessions, a few things in the release notes are the sort of change that turns a silent problem into a visible one:

  • fclose(), file_put_contents() and copy() now return false when flushing or closing fails. Before, a write could fail at the last step and still look fine.
  • Many functions now throw ValueError for out-of-range values, invalid flags or NUL bytes, rather than shrugging and carrying on.
  • trim(), ltrim() and rtrim() now strip form feed characters by default. Tiny, but if you compare trimmed strings against stored values, it's the kind of thing that changes a result.

There's also a long list of deprecations, including mb_ereg() and mb_split(), aliases like is_integer() and doubleval(), and spl_object_hash(). They won't break anything today. They're PHP telling you what will break later.

What I'd actually do

You don't need to rush to 8.6. It's supported for active fixes until the end of 2028 and security fixes until the end of 2030, so there's time to do it properly. The date that matters more right now is 31 December 2026, when PHP 8.2 stops getting security fixes. PHP 8.1 and older already get nothing from the PHP project. If you're on any of those, that's the job for this winter, and you may as well aim straight past 8.4 and 8.5 to 8.6.

Either way, the order is the same:

  • Get the app running on a copy of production with the new PHP version, not on the live server.
  • Turn on deprecation notices and read them. They're a free to-do list.
  • Test every login route, especially single sign-on, anything embedded on another site, and anything where another service sends the user back to you.
  • Look for code that writes files and ignores the result.
  • Check what your php.ini actually sets, for both the command line and the web server.

Also make sure you've applied this week's security releases. PHP 8.5.13, 8.4.28, 8.3.37 and 8.2.36 came out on the same day as 8.6, and they're security releases. I've written about that update in more detail over on rob-sherwood.co.uk.

If the app is older and nobody's quite sure what's in it, our page on upgrading old PHP to PHP 8 covers what usually breaks and how to tell a small job from a big one.

If you'd like a hand

If you've got a PHP app you'd rather someone else checked before the upgrade, our code audit is £250 + VAT. We read the code, the server and the way it gets deployed, and you get a written report with a fixed price for each fix. If you'd rather not think about PHP versions at all, Look after it covers security updates, hosting and backups from £355 a month + VAT. And if the person who wrote the app has moved on, we're happy to take it on.

Drop us a line and tell us what you're running.

Cheers, Rob

Tell us what you've got

It goes straight to Rob and Jase. You'll hear back from one of us, usually the same day, and we'll tell you honestly whether we're the right people.

Just want it checked? Code audit, £250 + VAT