{"id":"2fea4c62601a0a05","repo":"laravel/framework","slug":"abstract-is-aliased-to-itself","errorCode":null,"errorMessage":"[{$abstract}] is aliased to itself.","messagePattern":"\\[(.+?)\\] is aliased to itself\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Container/Container.php","lineNumber":696,"sourceCode":"            foreach ($this->tags[$tag] as $abstract) {\n                yield $this->make($abstract);\n            }\n        }, count($this->tags[$tag]));\n    }\n\n    /**\n     * Alias a type to a different name.\n     *\n     * @param  string  $abstract\n     * @param  string  $alias\n     * @return void\n     *\n     * @throws \\LogicException\n     */\n    public function alias($abstract, $alias)\n    {\n        if ($alias === $abstract) {\n            throw new LogicException(\"[{$abstract}] is aliased to itself.\");\n        }\n\n        $this->removeAbstractAlias($alias);\n\n        $this->aliases[$alias] = $abstract;\n\n        $this->abstractAliases[$abstract][] = $alias;\n    }\n\n    /**\n     * Bind a new callback to an abstract's rebind event.\n     *\n     * @param  string  $abstract\n     * @return mixed\n     */\n    public function rebinding($abstract, Closure $callback)\n    {\n        $this->reboundCallbacks[$abstract = $this->getAlias($abstract)][] = $callback;","sourceCodeStart":678,"sourceCodeEnd":714,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Container/Container.php#L678-L714","documentation":"Thrown by Container::alias when the $alias argument equals the $abstract argument. Aliasing a name to itself is a no-op that would create an infinite-resolution loop, so Laravel rejects it with a LogicException.","triggerScenarios":"Calling $container->alias('App\\Contracts\\Payment', 'App\\Contracts\\Payment') or $container->alias($iface, $iface) where both arguments are the same string.","commonSituations":"Programmatically building aliases from a map that accidentally maps an interface to itself; a service provider that aliases a binding to its own key; refactoring that leaves self-referential alias config.","solutions":["Ensure the alias name differs from the abstract: $container->alias(Payment::class, 'payment').","Guard the call: if ($alias !== $abstract) $container->alias($abstract, $alias).","Skip aliasing entirely if you only need the concrete to be resolvable by its own class name."],"exampleFix":"// before\n$container->alias($interface, $interface);\n\n// after\nif ($alias !== $abstract) {\n    $container->alias($abstract, $alias);\n}","handlingStrategy":"validation","validationCode":"if ($alias === $abstract) {\n    throw new \\LogicException(\"Cannot alias {$abstract} to itself\");\n}\n$container->alias($abstract, $alias);","typeGuard":"function isNonSelfAlias(string $abstract, string $alias): bool\n{\n    return $abstract !== $alias;\n}","tryCatchPattern":null,"preventionTips":["Guard alias() calls with a strict inequality check.","Generate aliases from a config map you validate once at boot.","Avoid aliasing in multiple providers to prevent cross-references."],"tags":["container","alias","configuration","di"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}