laravel/framework · error · LogicException

[ ] is aliased to itself.

Error message

[{$abstract}] is aliased to itself.

What it means

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.

Solutions

  1. Pick an alias string that genuinely differs from the abstract, e.g. alias(Cache::class, 'cache').
  2. Guard the call when alias may equal abstract: if ($alias !== $abstract) $container->alias($abstract, $alias).
  3. Review the config/service-provider list producing the alias and remove the redundant entry.

Example fix

// before
$app->alias(PaymentGateway::class, PaymentGateway::class);
// after
$app->alias(PaymentGateway::class, 'gateway');
Defensive patterns

Strategy: validation

Validate before calling

if ($alias === $abstract) {
    // skip or pick a different alias
    return;
}
$container->alias($abstract, $alias);

Type guard

function shouldAlias(string $abstract, string $alias): bool
{
    return $abstract !== $alias;
}

Try / catch

try {
    $container->alias($abstract, $alias);
} catch (\LogicException $e) {
    if (str_contains($e->getMessage(), 'aliased to itself')) {
        // choose a distinct alias and retry
    }
    throw $e;
}

Prevention

When it happens

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

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

Related errors


AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11). Data as JSON: /api/errors/2fea4c62601a0a05. Report an issue: GitHub.

Appendix: 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 e0f6eb3518)