symfony/routing · error · InvalidArgumentException

Class " " does not exist.

Error message

Class "%s" does not exist.

What it means

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.

Solutions

  1. Fix the class name string (fully-qualified, correct case and namespace)
  2. Ensure composer autoload covers the class (dump-autoload / register the namespace)
  3. Pass $class::class of an actual instance instead of a wrong string

Example fix

// before
$loader->load('App\Controller\ProductControlelr');
// after
$loader->load('App\Controller\ProductController');
Defensive patterns

Strategy: type-guard

Validate before calling

if (!class_exists($class) && !interface_exists($class)) {
    throw new \InvalidArgumentException("Controller class '$class' does not exist or is not autoloadable");
}

Type guard

function classIsLoadable(string $class): bool {
    return class_exists($class);
}

Try / catch

try {
    $collection = $loader->load($class);
} catch (\InvalidArgumentException $e) {
    // log the bad controller reference
}

Prevention

When it happens

Trigger: $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.

Common situations: 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.

Related errors


AI-assisted analysis of symfony/routing@83fa223250 (2026-09-14). Data as JSON: /api/errors/057e14f2d1566612. Report an issue: GitHub.

Appendix: source

Thrown at Loader/AttributeClassLoader.php:80

        protected readonly ?string $env = null,
    ) {
    }

    /**
     * Sets the attribute class to read route properties from.
     */
    public function setRouteAttributeClass(string $class): void
    {
        $this->routeAttributeClass = $class;
    }

    /**
     * @throws \InvalidArgumentException When route can't be parsed
     */
    public function load(mixed $class, ?string $type = null): RouteCollection
    {
        if (!class_exists($class)) {
            throw new \InvalidArgumentException(\sprintf('Class "%s" does not exist.', $class));
        }

        $class = new \ReflectionClass($class);
        if ($class->isAbstract()) {
            throw new \InvalidArgumentException(\sprintf('Attributes from class "%s" cannot be read as it is abstract.', $class->getName()));
        }

        $globals = $this->getGlobals($class);
        $collection = new RouteCollection();
        $collection->addResource(new ReflectionClassResource($class));
        if ($globals['env'] && !\in_array($this->env, $globals['env'], true)) {
            return $collection;
        }
        $fqcnAlias = false;

        if (!$class->hasMethod('__invoke')) {
            foreach ($this->getAttributes($class) as $attr) {
                if ($attr->aliases) {

View on GitHub (pinned to 83fa223250)