{"record":{"id":"9919a383f5c712e4","repo":"symfony/routing","slug":"cannot-serialize-loader-configurator-importconfigurator","errorCode":null,"errorMessage":"Cannot serialize Loader\\Configurator\\ImportConfigurator","messagePattern":"Cannot serialize Loader\\\\Configurator\\\\ImportConfigurator","errorType":"exception","errorClass":"BadMethodCallException","httpStatus":null,"severity":"error","filePath":"Loader/Configurator/ImportConfigurator.php","lineNumber":34,"sourceCode":"/**\n * @author Nicolas Grekas <p@tchwork.com>\n */\nclass ImportConfigurator\n{\n    use Traits\\HostTrait;\n    use Traits\\PrefixTrait;\n    use Traits\\RouteTrait;\n\n    public function __construct(\n        private RouteCollection $parent,\n        RouteCollection $route,\n    ) {\n        $this->route = $route;\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        $this->parent->addCollection($this->route);\n    }\n\n    /**\n     * Sets the prefix to add to the path of all child routes.\n     *\n     * @param string|array $prefix the prefix, or the localized prefixes\n     *\n     * @return $this","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/symfony/routing/blob/83fa223250b50f4f018c011e101c330e65ac63cc/Loader/Configurator/ImportConfigurator.php#L16-L52","documentation":"ImportConfigurator explicitly forbids serialization via __serialize(), throwing BadMethodCallException. This object holds a live RouteCollection and parent configurator, so serializing it would produce a broken or inconsistent copy; the library treats serialization of it as a programming error.","triggerScenarios":"Calling serialize($configurator), var_export/var_dump with serialization side effects, putting an ImportConfigurator in a cache pool or session, or otherwise letting PHP call __serialize() on an ImportConfigurator instance created by CollectionConfigurator::add().","commonSituations":"Caching route configurator objects, using serialize() to debug route configuration, passing configurators through workflows that clone or persist objects (sessions, queues, var_export-based dumping).","solutions":["Do not serialize the ImportConfigurator; serialize only the resulting RouteCollection or the raw config array used to build routes.","Rebuild the configurator from configuration (CollectionConfigurator::add()) instead of persisting instances.","If you need dumping, use methods that do not rely on serialization (e.g. inspect the route collection directly)."],"exampleFix":"// before\n$cache->set('routes_config', $importConfigurator);\n// after\n$cache->set('routes_collection', $collectionConfigurator->build());","handlingStrategy":"try-catch","validationCode":"if ($obj instanceof \\Symfony\\Component\\Routing\\Loader\\Configurator\\ImportConfigurator) { /* never serialize */ }","typeGuard":"function serializable(mixed $v): bool { return !$v instanceof \\Symfony\\Component\\Routing\\Loader\\Configurator\\ImportConfigurator; }","tryCatchPattern":"try { serialize($cfg); } catch (\\BadMethodCallException $e) { /* rebuild from config instead */ }","preventionTips":["Never place routing configurator objects in cache/session/queues.","Persist RouteCollection or config arrays, not live configurator objects.","Prefer var_dump/print_r-free debugging of these objects (no serialize side effects)."],"tags":["routing","serialization","bad-method-call","symfony"],"backgroundTag":"json-serialization-failed","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"}