{"record":{"id":"057e14f2d1566612","repo":"symfony/routing","slug":"class-s-does-not-exist","errorCode":null,"errorMessage":"Class \"%s\" does not exist.","messagePattern":"Class \"(.+?)\" does not exist\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Loader/AttributeClassLoader.php","lineNumber":80,"sourceCode":"        protected readonly ?string $env = null,\n    ) {\n    }\n\n    /**\n     * Sets the attribute class to read route properties from.\n     */\n    public function setRouteAttributeClass(string $class): void\n    {\n        $this->routeAttributeClass = $class;\n    }\n\n    /**\n     * @throws \\InvalidArgumentException When route can't be parsed\n     */\n    public function load(mixed $class, ?string $type = null): RouteCollection\n    {\n        if (!class_exists($class)) {\n            throw new \\InvalidArgumentException(\\sprintf('Class \"%s\" does not exist.', $class));\n        }\n\n        $class = new \\ReflectionClass($class);\n        if ($class->isAbstract()) {\n            throw new \\InvalidArgumentException(\\sprintf('Attributes from class \"%s\" cannot be read as it is abstract.', $class->getName()));\n        }\n\n        $globals = $this->getGlobals($class);\n        $collection = new RouteCollection();\n        $collection->addResource(new ReflectionClassResource($class));\n        if ($globals['env'] && !\\in_array($this->env, $globals['env'], true)) {\n            return $collection;\n        }\n        $fqcnAlias = false;\n\n        if (!$class->hasMethod('__invoke')) {\n            foreach ($this->getAttributes($class) as $attr) {\n                if ($attr->aliases) {","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/symfony/routing/blob/83fa223250b50f4f018c011e101c330e65ac63cc/Loader/AttributeClassLoader.php#L62-L98","documentation":"AttributeClassLoader::load() expects a fully-qualified class name string; if class_exists($class) fails it throws an InvalidArgumentException. This means the given class does not exist or is not autoloadable at the time of loading.","triggerScenarios":"$loader->load('App\\\\Controller\\\\MissingController') where the class is misspelled, lacks a namespace prefix, or the autoloader isn't registered; passing an object instead of its class-string; loading a controller from a bundle not yet registered.","commonSituations":"Typos in #[Route(..., controller: ...)] or YAML controllers referencing missing classes; forgetting to import/register the controller's namespace; running loaders in a script without composer autoload.","solutions":["Fix the class name string (fully-qualified, correct case and namespace)","Ensure composer autoload covers the class (dump-autoload / register the namespace)","Pass $class::class of an actual instance instead of a wrong string"],"exampleFix":"// before\n$loader->load('App\\Controller\\ProductControlelr');\n// after\n$loader->load('App\\Controller\\ProductController');","handlingStrategy":"type-guard","validationCode":"if (!class_exists($class) && !interface_exists($class)) {\n    throw new \\InvalidArgumentException(\"Controller class '$class' does not exist or is not autoloadable\");\n}","typeGuard":"function classIsLoadable(string $class): bool {\n    return class_exists($class);\n}","tryCatchPattern":"try {\n    $collection = $loader->load($class);\n} catch (\\InvalidArgumentException $e) {\n    // log the bad controller reference\n}","preventionTips":["Use ::class constants instead of raw strings for controller references","Run composer dump-autoload and lint routing config in CI","Check debug:router output for unresolvable controller references"],"tags":["php","routing","loader","attributes","autoload"],"backgroundTag":"class-not-found","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"}