{"record":{"id":"26c7a26ad84a1bde","repo":"symfony/http-foundation","slug":"the-session-handler-s-does-not-support-clearing-all-sessions-26c7a2","errorCode":null,"errorMessage":"The session handler \"%s\" does not support clearing all sessions.","messagePattern":"The session handler \"(.+?)\" does not support clearing all sessions\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"Session/Storage/Handler/MigratingSessionHandler.php","lineNumber":111,"sourceCode":"    {\n        // No reading from new handler until switch-over\n        return $this->currentHandler->validateId($sessionId);\n    }\n\n    public function updateTimestamp(#[\\SensitiveParameter] string $sessionId, string $sessionData): bool\n    {\n        $result = $this->currentHandler->updateTimestamp($sessionId, $sessionData);\n        $this->writeOnlyHandler->updateTimestamp($sessionId, $sessionData);\n\n        return $result;\n    }\n\n    public function clear(): void\n    {\n        if ($this->currentHandler instanceof ClearableSessionHandlerInterface) {\n            $this->currentHandler->clear();\n        } else {\n            throw new \\LogicException(\\sprintf('The session handler \"%s\" does not support clearing all sessions.', get_debug_type($this->currentHandler)));\n        }\n\n        if ($this->writeOnlyHandler instanceof ClearableSessionHandlerInterface) {\n            $this->writeOnlyHandler->clear();\n        }\n    }\n}\n","sourceCodeStart":93,"sourceCodeEnd":119,"githubUrl":"https://github.com/symfony/http-foundation/blob/5aea19cd678fa4140f6108406f1096de5e9ed6e4/Session/Storage/Handler/MigratingSessionHandler.php#L93-L119","documentation":"MigratingSessionHandler wraps a read/write handler and a write-only handler (used when migrating session storage). The clear() method wipes all sessions, but it can only do so if the current handler implements ClearableSessionHandlerInterface; otherwise it throws a LogicException naming the offending handler class.","triggerScenarios":"Calling MigratingSessionHandler::clear() when the current (read) handler does not implement ClearableSessionHandlerInterface, e.g. wrapping a legacy custom \\SessionHandlerInterface handler that lacks a clear() method.","commonSituations":"Calling $session->clear() or invalidating all sessions while a migration is configured with a non-clearable legacy handler; custom handlers written before ClearableSessionHandlerInterface existed; third-party session handlers that never added clear().","solutions":["Make the current handler implement Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\ClearableSessionHandlerInterface and add a clear(): void method.","Replace the current handler with a built-in clearable handler (e.g. NativeFileSessionHandler, PdoSessionHandler, RedisSessionHandler where supported).","Wrap the call in a LogicException guard and skip/fallback to per-session destroy when clear is unsupported.","Upgrade the third-party session handler package to a version that implements ClearableSessionHandlerInterface."],"exampleFix":"// before\nclass LegacyHandler implements \\SessionHandlerInterface { /* no clear() */ }\n$handler = new MigratingSessionHandler(new LegacyHandler(), new PdoSessionHandler($pdo));\n$handler->clear(); // throws\n\n// after\nclass LegacyHandler implements \\SessionHandlerInterface, ClearableSessionHandlerInterface {\n    public function clear(): void { /* delete all sessions */ }\n}\n$handler = new MigratingSessionHandler(new LegacyHandler(), new PdoSessionHandler($pdo));\n$handler->clear(); // works","handlingStrategy":"try-catch","validationCode":"if (!$currentHandler instanceof \\Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\ClearableSessionHandlerInterface) {\n    throw new \\LogicException('Handler does not support clear(); skip or migrate first.');\n}","typeGuard":"function isClearable($handler): bool {\n    return $handler instanceof \\Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\ClearableSessionHandlerInterface;\n}","tryCatchPattern":"try {\n    $migratingHandler->clear();\n} catch (\\LogicException $e) {\n    // fall back to per-session destroy or log and skip\n}","preventionTips":["Always implement ClearableSessionHandlerInterface in custom session handlers.","Check the interface before calling clear() on wrapped handlers.","Prefer built-in clearable handlers during migrations."],"tags":["sessions","php","logic-exception","handler-migration"],"backgroundTag":"unsupported-operation","analyzedSha":"5aea19cd678fa4140f6108406f1096de5e9ed6e4","analyzedAt":"2026-09-13T01:52:22.855Z","contentChangedAt":"2026-09-13T01:52:22.855Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}