{"record":{"id":"9de386416ac62321","repo":"symfony/http-foundation","slug":"the-session-handler-s-does-not-support-clearing-all-sessions","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/MarshallingSessionHandler.php","lineNumber":94,"sourceCode":"    public function validateId(#[\\SensitiveParameter] string $sessionId): bool\n    {\n        return $this->handler->validateId($sessionId);\n    }\n\n    public function updateTimestamp(#[\\SensitiveParameter] string $sessionId, string $data): bool\n    {\n        return $this->handler->updateTimestamp($sessionId, $data);\n    }\n\n    public function clear(): void\n    {\n        if ($this->handler instanceof ClearableSessionHandlerInterface) {\n            $this->handler->clear();\n\n            return;\n        }\n\n        throw new \\LogicException(\\sprintf('The session handler \"%s\" does not support clearing all sessions.', get_debug_type($this->handler)));\n    }\n}\n","sourceCodeStart":76,"sourceCodeEnd":97,"githubUrl":"https://github.com/symfony/http-foundation/blob/5aea19cd678fa4140f6108406f1096de5e9ed6e4/Session/Storage/Handler/MarshallingSessionHandler.php#L76-L97","documentation":"MarshallingSessionHandler::clear() clears all sessions, but only if the wrapped inner handler implements ClearableSessionHandlerInterface. Otherwise it throws LogicException naming the handler's debug type. This is a capability check: bulk clearing is optional for session handlers, so unsupported handlers are rejected rather than silently failing.","triggerScenarios":"Calling MarshallingSessionHandler::clear() when the inner handler (e.g. PdoSessionHandler, MemcachedSessionHandler, or any plain \\SessionHandler) does not implement ClearableSessionHandlerInterface.","commonSituations":"Wrapping a third-party or built-in session handler without a clear() capability and calling session-level 'clear all sessions' logic (e.g. admin 'log out all users' feature); upgrading code that assumed the inner handler was clearable.","solutions":["Wrap/replace the inner handler with one implementing ClearableSessionHandlerInterface","Check `$handler instanceof ClearableSessionHandlerInterface` before calling clear() and handle the unsupported case (e.g. iterate and destroy session ids individually)","Implement the interface on a custom inner handler","Remove the clear() call or feature when the storage backend cannot bulk-clear"],"exampleFix":"// before\n$marshallingHandler->clear(); // LogicException if inner handler not clearable\n// after\nif ($marshallingHandler instanceof ClearableSessionHandlerInterface || $innerHandler instanceof ClearableSessionHandlerInterface) {\n    $marshallingHandler->clear();\n} else {\n    throw new UnsupportedSessionOperationException('Clearing all sessions is not supported by this handler.');\n}","handlingStrategy":"type-guard","validationCode":"if (!$innerHandler instanceof ClearableSessionHandlerInterface) {\n    throw new LogicException(sprintf('Handler %s cannot clear all sessions; use a clearable handler or destroy sessions individually.', get_debug_type($innerHandler)));\n}","typeGuard":"function isClearable(object $handler): bool\n{\n    return $handler instanceof ClearableSessionHandlerInterface;\n}","tryCatchPattern":"try {\n    $marshallingHandler->clear();\n} catch (\\LogicException $e) {\n    if (str_contains($e->getMessage(), 'does not support clearing all sessions')) {\n        // fallback: destroy known session ids or skip the bulk-clear feature\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Check ClearableSessionHandlerInterface on the inner handler before exposing bulk-clear features","Choose clearable backends (e.g. ones with native flush) for 'log out all users' style features","Keep a fallback path (iterate + destroy) for non-clearable handlers","Add an interface assertion in application boot/config validation"],"tags":["session","unsupported-operation","php"],"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"}