laravel/framework · error · LogicException
[{$abstract}] is aliased to itself.
Error message
[{$abstract}] is aliased to itself. What it means
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.
Source
Thrown at src/Illuminate/Container/Container.php:696
foreach ($this->tags[$tag] as $abstract) {
yield $this->make($abstract);
}
}, count($this->tags[$tag]));
}
/**
* Alias a type to a different name.
*
* @param string $abstract
* @param string $alias
* @return void
*
* @throws \LogicException
*/
public function alias($abstract, $alias)
{
if ($alias === $abstract) {
throw new LogicException("[{$abstract}] is aliased to itself.");
}
$this->removeAbstractAlias($alias);
$this->aliases[$alias] = $abstract;
$this->abstractAliases[$abstract][] = $alias;
}
/**
* Bind a new callback to an abstract's rebind event.
*
* @param string $abstract
* @return mixed
*/
public function rebinding($abstract, Closure $callback)
{
$this->reboundCallbacks[$abstract = $this->getAlias($abstract)][] = $callback;View on GitHub (pinned to bd6b5437e6)
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.
Example fix
// before
$container->alias($interface, $interface);
// after
if ($alias !== $abstract) {
$container->alias($abstract, $alias);
} Defensive patterns
Strategy: validation
Validate before calling
if ($alias === $abstract) {
throw new \LogicException("Cannot alias {$abstract} to itself");
}
$container->alias($abstract, $alias); Type guard
function isNonSelfAlias(string $abstract, string $alias): bool
{
return $abstract !== $alias;
} Prevention
- 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.
When it happens
Trigger: Calling $container->alias('App\Contracts\Payment', 'App\Contracts\Payment') or $container->alias($iface, $iface) where both arguments are the same string.
Common situations: 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.
Related errors
- Circular alias reference for [{$abstract}].
- Unresolvable dependency resolving [$parameter] in class {$pa
- The environment property must be set and cannot be empty.
- Method not provided.
- Unable to resolve dependency [{$parameter}] in class {$param
AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06).
Data as JSON: /data/errors/2fea4c62601a0a05.json.
Report an issue: GitHub.