{"record":{"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/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Container/Container.php#L678-L714","documentation":"A LogicException from Container::alias() when the alias and the abstract are the same string. Aliasing a name to itself is meaningless and would create a self-referential entry, so the framework rejects it outright.","triggerScenarios":"Calling $container->alias('App\\Contracts\\Cache', 'App\\Contracts\\Cache'); aliasing where both arguments resolve to the same class string; dynamic code that computes alias and abstract from the same source value.","commonSituations":"Auto-generating aliases from config where the alias and target accidentally coincide; refactoring a class so a previously-distinct alias now equals the FQCN; misconfigured service provider alias lists.","solutions":["Pick an alias string that genuinely differs from the abstract, e.g. alias(Cache::class, 'cache').","Guard the call when alias may equal abstract: if ($alias !== $abstract) $container->alias($abstract, $alias).","Review the config/service-provider list producing the alias and remove the redundant entry."],"exampleFix":"// before\n$app->alias(PaymentGateway::class, PaymentGateway::class);\n// after\n$app->alias(PaymentGateway::class, 'gateway');","handlingStrategy":"validation","validationCode":"if ($alias === $abstract) {\n    // skip or pick a different alias\n    return;\n}\n$container->alias($abstract, $alias);","typeGuard":"function shouldAlias(string $abstract, string $alias): bool\n{\n    return $abstract !== $alias;\n}","tryCatchPattern":"try {\n    $container->alias($abstract, $alias);\n} catch (\\LogicException $e) {\n    if (str_contains($e->getMessage(), 'aliased to itself')) {\n        // choose a distinct alias and retry\n    }\n    throw $e;\n}","preventionTips":["Never auto-alias to the same value; guard dynamic alias generation.","Keep aliases as short human-friendly keys, distinct from FQCNs.","Review all alias() calls in service providers during code review."],"tags":["container","alias","configuration"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}