[{"data":1,"prerenderedAt":6},["ShallowReactive",2],{"post-content-php-8-6-session-defaults-upgrade":3},{"content":4,"lastModified":5},"\u003Cp>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.\u003C\u002Fp>\n\n\u003Cp>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 \u003Ccode>ext\u002Fsession\u002Fsession.c\u003C\u002Fcode>.\u003C\u002Fp>\n\n\u003Cfigure>\n  \u003Cimg src=\"https:\u002F\u002Fimages.pexels.com\u002Fphotos\u002F37050930\u002Fpexels-photo-37050930.jpeg?auto=compress&amp;cs=tinysrgb&amp;w=1200\" alt=\"A railway switch machine between two numbered tracks, with a red signal lamp lit beside the rails\" loading=\"lazy\" \u002F>\n\u003C\u002Ffigure>\n\n\u003Ch2>The defaults moved and your config did not\u003C\u002Fh2>\n\n\u003Cp>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:\u003C\u002Fp>\n\n\u003Cpre>\u003Ccode class=\"language-c\">STD_PHP_INI_BOOLEAN(\"session.cookie_httponly\", \"1\", ...)\nSTD_PHP_INI_ENTRY(\"session.cookie_samesite\",   \"Lax\", ...)\nSTD_PHP_INI_BOOLEAN(\"session.use_strict_mode\", \"1\", ...)\u003C\u002Fcode>\u003C\u002Fpre>\n\n\u003Cp>In 8.5 those read \u003Ccode>\"0\"\u003C\u002Fcode>, \u003Ccode>\"\"\u003C\u002Fcode> and \u003Ccode>\"0\"\u003C\u002Fcode>. 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.\u003C\u002Fp>\n\n\u003Cp>Check before you swap, on every box, because FPM pool settings override php.ini and that is usually where this gets decided:\u003C\u002Fp>\n\n\u003Cpre>\u003Ccode class=\"language-bash\">php -i | grep '^session\\.' | grep -E 'strict_mode|httponly|samesite'\u003C\u002Fcode>\u003C\u002Fpre>\n\n\u003Cp>On the 8.0.30 build I keep around for this kind of question, that prints \u003Ccode>0\u003C\u002Fcode>, \u003Ccode>no value\u003C\u002Fcode>, \u003Ccode>no value\u003C\u002Fcode>. Anything showing \u003Ccode>1\u003C\u002Fcode>, \u003Ccode>1\u003C\u002Fcode>, \u003Ccode>Lax\u003C\u002Fcode> 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.\u003C\u002Fp>\n\n\u003Ch2>Strict mode only works if your handler can answer\u003C\u002Fh2>\n\n\u003Cp>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 \u003Ccode>validateId()\u003C\u002Fcode>:\u003C\u002Fp>\n\n\u003Cpre>\u003Ccode class=\"language-c\">} else if (PS(use_strict_mode) &amp;&amp; PS(mod)->s_validate_sid &amp;&amp;\n    PS(mod)->s_validate_sid(&amp;PS(mod_data), PS(id)) == FAILURE\n) {\u003C\u002Fcode>\u003C\u002Fpre>\n\n\u003Cp>No \u003Ccode>s_validate_sid\u003C\u002Fcode>, no branch. The ID from the cookie is adopted, same as before. So if you registered your own Redis or Memcached handler that implements \u003Ccode>SessionHandlerInterface\u003C\u002Fcode> and nothing else, strict mode has been decoration for years and switching it on by default changes nothing. The directive reads \u003Ccode>1\u003C\u002Fcode> while your app keeps trusting whatever ID the client hands it.\u003C\u002Fp>\n\n\u003Cp>8.6 makes this loud in two directions. First, \u003Ccode>SessionHandler::validateId()\u003C\u002Fcode> is new, so wrapping an internal handler with \u003Ccode>SessionHandler\u003C\u002Fcode> 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 \u003Ccode>SessionHandlerInterface\u003C\u002Fcode> without defining both \u003Ccode>create_sid()\u003C\u002Fcode> and \u003Ccode>validateId()\u003C\u002Fcode> now prints a warning for each missing method:\u003C\u002Fp>\n\n\u003Cblockquote>\u003Cp>Class Foo implementing SessionHandlerInterface is missing the validateId() method which will be required in PHP 9.0\u003C\u002Fp>\u003C\u002Fblockquote>\n\n\u003Cp>It fires when the class is linked, not when a session starts, so you will see it on requests that never touch \u003Ccode>$_SESSION\u003C\u002Fcode>. If \u003Ccode>display_errors\u003C\u002Fcode> is on anywhere near production, it ends up in the HTML.\u003C\u002Fp>\n\n\u003Ch2>SameSite=Lax and the callback that POSTs\u003C\u002Fh2>\n\n\u003Cp>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.\u003C\u002Fp>\n\n\u003Cp>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.\u003C\u002Fp>\n\n\u003Cp>If a flow needs it back, be precise: \u003Ccode>session.cookie_samesite=None\u003C\u002Fcode> plus \u003Ccode>session.cookie_secure=1\u003C\u002Fcode>, on the routes that need it. Loosening the whole application to None to rescue one callback trades a login bug for a CSRF one.\u003C\u002Fp>\n\n\u003Cp>Laravel people get a slightly different deal. \u003Ccode>config\u002Fsession.php\u003C\u002Fcode> already sets \u003Ccode>http_only\u003C\u002Fcode> and \u003Ccode>same_site\u003C\u002Fcode>, so those two flips land on values you wrote yourself. \u003Ccode>session.use_strict_mode\u003C\u002Fcode> is not in that file because it is an engine directive, so it is the one that changes without the framework noticing.\u003C\u002Fp>\n\n\u003Ch2>The parts of 8.6 I will actually use\u003C\u002Fh2>\n\n\u003Cp>Partial application removes a category of pointless arrow functions. \u003Ccode>?\u003C\u002Fcode> fills one argument position, \u003Ccode>...\u003C\u002Fcode> fills whatever is left, and you get a Closure back:\u003C\u002Fp>\n\n\u003Cpre>\u003Ccode class=\"language-php\">$slugify = str_replace(' ', '-', ?);\necho $slugify('Hello World');  \u002F\u002F Hello-World\n\n$titles = array_map(strtolower(?), $titles);\u003C\u002Fcode>\u003C\u002Fpre>\n\n\u003Cp>Arguments you do supply are evaluated when the partial is built, not when it is called, so do not park \u003Ccode>getenv()\u003C\u002Fcode> in there and expect it to be read later.\u003C\u002Fp>\n\n\u003Cp>\u003Ccode>clamp()\u003C\u002Fcode> is the helper everyone has written by hand. This one throws \u003Ccode>ValueError\u003C\u002Fcode> when \u003Ccode>min\u003C\u002Fcode> exceeds \u003Ccode>max\u003C\u002Fcode> instead of returning something weird, and it hands back the original type unconverted, so keep your numerics numeric.\u003C\u002Fp>\n\n\u003Cp>Readonly properties can take a default now, retiring constructors that existed only to assign a constant. One small thing with teeth: \u003Ccode>trim()\u003C\u002Fcode>, \u003Ccode>rtrim()\u003C\u002Fcode> and \u003Ccode>ltrim()\u003C\u002Fcode> now strip a form feed by default, so anything parsing fixed-width or imported text should spell out its character list.\u003C\u002Fp>\n\n\u003Ch2>What I would do on the 18th\u003C\u002Fh2>\n\n\u003Cp>Diff \u003Ccode>php -i\u003C\u002Fcode> between the two binaries on one machine. Grep for \u003Ccode>session_set_save_handler\u003C\u002Fcode> and check whether those classes define \u003Ccode>validateId()\u003C\u002Fcode>. Then walk a cross-site callback through a browser by hand.\u003C\u002Fp>\n\n\u003Cp>Half an hour, and it covers the only two ways this release can hurt you quietly.\u003C\u002Fp>\n\n\u003Cp>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 \u003Ca href=\"\u002Fsnippetark\u002F\">Snippet Ark\u003C\u002Fa> for the next upgrade window. If session handling has bitten you before, the \u003Ca href=\"\u002Fposts\u002Flaravel-sanctum-401-after-login-stateful-domains\u002F\">Sanctum stateful domains\u003C\u002Fa> mess is the same bug in a different hat.\u003C\u002Fp>\n","2026-11-18",1795678594117]