{"record":{"id":"e970a0b1d7d1c40e","repo":"symfony/symfony","slug":"cannot-unserialize-class-e970a0","errorCode":null,"errorMessage":"Cannot unserialize {class}","messagePattern":"Cannot unserialize (.+?)","errorType":"exception","errorClass":"BadMethodCallException","httpStatus":null,"severity":"error","filePath":"src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php","lineNumber":178,"sourceCode":"                }\n\n                foreach (@scandir($dir, \\SCANDIR_SORT_NONE) ?: [] as $file) {\n                    if ('.' !== $file && '..' !== $file) {\n                        yield $dir.\\DIRECTORY_SEPARATOR.$file;\n                    }\n                }\n            }\n        }\n    }\n\n    public function __serialize(): array\n    {\n        throw new \\BadMethodCallException('Cannot serialize '.__CLASS__);\n    }\n\n    public function __unserialize(array $data): void\n    {\n        throw new \\BadMethodCallException('Cannot unserialize '.__CLASS__);\n    }\n\n    public function __destruct()\n    {\n        parent::__destruct();\n        if (isset($this->tmpSuffix) && is_file($this->directory.$this->tmpSuffix)) {\n            unlink($this->directory.$this->tmpSuffix);\n        }\n    }\n}\n","sourceCodeStart":160,"sourceCodeEnd":189,"githubUrl":"https://github.com/symfony/symfony/blob/3b11ffbe2520436b0951974d1993dc2144f91dd3/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php#L160-L189","documentation":"This BadMethodCallException is thrown by FilesystemCommonTrait::__unserialize. Since FilesystemAdapter objects are non-serializable by design (__serialize also throws), reaching __unserialize indicates an attempt to rehydrate an adapter from a payload that cannot represent a valid live pool (directory path, open handles, scratch files). The trait rejects this to avoid operating with broken state.","triggerScenarios":"Calling unserialize() on a byte string meant to represent a FilesystemAdapter; generic object hydrators that materialize every object in a payload; restoring state from a previous Symfony version or test snapshot.","commonSituations":"A generic object cache or session handler that round-trips arbitrary objects; migration between Symfony versions where adapter internals changed; stale serialized fixtures.","solutions":["Rebuild filesystem cache adapters from configuration (namespace + directory) at runtime; do not restore them via unserialize.","If hit during migration, drop the stale payload and let the app recreate the pool.","Audit unserialize call sites and exclude cache services from the round-trip."],"exampleFix":"// before\n$adapter = unserialize($blob); // throws\n\n// after\n$adapter = new FilesystemAdapter($namespace, 0, $directory);","handlingStrategy":"validation","validationCode":"if (preg_match('/^O:\\d+:\"Symfony\\\\\\Component\\\\\\Cache\\\\\\Adapter\\\\\\FilesystemAdapter\"/', $blob)) {\n    throw new \\RuntimeException('Refusing to unserialize a FilesystemAdapter payload.');\n}","typeGuard":null,"tryCatchPattern":"try {\n    $obj = unserialize($blob);\n} catch (\\BadMethodCallException $e) {\n    $obj = new FilesystemAdapter($namespace, 0, $directory);\n}","preventionTips":["Never restore filesystem adapters via unserialize.","Rebuild the adapter from its config (namespace, directory).","Audit generic unserialize call sites for stale cache-service payloads."],"tags":["cache","serialization","forbidden-operation","stateful-object","filesystem"],"backgroundTag":null,"analyzedSha":"3b11ffbe2520436b0951974d1993dc2144f91dd3","analyzedAt":"2026-08-11T22:13:02.001Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}