{"record":{"id":"c363376676e0411f","repo":"symfony/routing","slug":"cannot-unserialize-symfony-component-routing-compiledroute","errorCode":null,"errorMessage":"Cannot unserialize Symfony\\Component\\Routing\\CompiledRoute","messagePattern":"Cannot unserialize Symfony\\\\Component\\\\Routing\\\\CompiledRoute","errorType":"exception","errorClass":"BadMethodCallException","httpStatus":null,"severity":"error","filePath":"CompiledRoute.php","lineNumber":63,"sourceCode":"        return [\n            'vars' => $this->variables,\n            'path_prefix' => $this->staticPrefix,\n            'path_regex' => $this->regex,\n            'path_tokens' => $this->tokens,\n            'path_vars' => $this->pathVariables,\n            'host_regex' => $this->hostRegex,\n            'host_tokens' => $this->hostTokens,\n            'host_vars' => $this->hostVariables,\n        ];\n    }\n\n    public function __unserialize(array $data): void\n    {\n        if (($data['path_prefix'] ?? null) instanceof \\Stringable\n            || ($data['path_regex'] ?? null) instanceof \\Stringable\n            || ($data['host_regex'] ?? null) instanceof \\Stringable\n        ) {\n            throw new \\BadMethodCallException('Cannot unserialize '.self::class);\n        }\n\n        $this->variables = $data['vars'];\n        $this->staticPrefix = $data['path_prefix'];\n        $this->regex = $data['path_regex'];\n        $this->tokens = $data['path_tokens'];\n        $this->pathVariables = $data['path_vars'];\n        $this->hostRegex = $data['host_regex'];\n        $this->hostTokens = $data['host_tokens'];\n        $this->hostVariables = $data['host_vars'];\n    }\n\n    /**\n     * Returns the static prefix.\n     */\n    public function getStaticPrefix(): string\n    {\n        return $this->staticPrefix;","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/symfony/routing/blob/83fa223250b50f4f018c011e101c330e65ac63cc/CompiledRoute.php#L45-L81","documentation":"CompiledRoute::__unserialize() rejects payloads whose path_prefix, path_regex or host_regex entries are Stringable objects — a format produced by old (pre-4.3-era object-based) serialized CompiledRoute data. This protects against unserializing incompatible legacy cache data; the valid format stores plain strings.","triggerScenarios":"unserialize() on a CompiledRoute payload generated by an older Symfony version, or a hand-crafted/modified serialized array containing Stringable values for the regex/prefix keys.","commonSituations":"Stale routing cache files surviving a major Symfony upgrade; serialized routes persisted in long-lived storage (e.g. DB) across framework upgrades.","solutions":["Clear and rebuild the cache (rm -rf var/cache/* then cache:warmup) so routes are re-serialized in the current format","Re-generate any persisted serialized CompiledRoute data after upgrading Symfony","Never unserialize CompiledRoute payloads of unknown provenance; store the Route/RouteCollection and compile on demand"],"exampleFix":"// before\n$route = unserialize($staleCacheData); // old format\n// after\nrm -rf var/cache/* && php bin/console cache:warmup","handlingStrategy":"try-catch","validationCode":"// pre-check legacy payloads before unserialize\n$data = unserialize($raw, ['allowed_classes' => [CompiledRoute::class]]);\nif (isset($data[\"path_prefix\"]) && is_object($data[\"path_prefix\"])) {\n    // stale/legacy format — rebuild instead of using\n}","typeGuard":null,"tryCatchPattern":"try {\n    $compiled = unserialize($raw);\n} catch (\\BadMethodCallException $e) {\n    $compiled = $route->compile(); // rebuild from Route\n}","preventionTips":["Clear routing caches after every Symfony upgrade","Don't persist serialized CompiledRoute objects long-term; persist Route and compile on demand","Regenerate cache in deployments"],"tags":["php","routing","unserialization","cache"],"backgroundTag":"incompatible-source-type","analyzedSha":"83fa223250b50f4f018c011e101c330e65ac63cc","analyzedAt":"2026-09-14T03:19:46.280Z","contentChangedAt":"2026-09-14T03:19:46.280Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}