phalcon/cphalcon · error · Phalcon\Di\Exceptions\CircularAliasReference

Circular alias reference detected while resolving

Error message

Circular alias reference detected while resolving '{name}'

What it means

Thrown by Di::resolveAlias while walking the alias chain: a name was revisited (tracked in the `seen` set), meaning aliases form a loop (a->b->a) that would otherwise loop forever. Fix by breaking the cycle in your alias definitions so every chain terminates at a real service name.

Solutions

  1. Break the cycle: make sure the last alias in the chain resolves to a real registered service
  2. Audit setAlias() calls and ensure no alias maps to another alias that maps back
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at phalcon/Di/Di.zep:736 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21). Data as JSON: /api/errors/a7f9d9524608d302. Report an issue: GitHub.

Appendix: source

Thrown at phalcon/Di/Di.zep:736

    }
    /**
     * Resolve an alias to its actual service name
     *
     * @param string $name
     *
     * @return string
     * @throws Exception
     */
    private function resolveAlias(string name) -> string
    {
        var current, seen;

        let current = name;
        let seen    = [];

        while (isset(this->aliases[current])) {
            if (isset(seen[current])) {
                throw new CircularAliasReference(name);
            }
            let seen[current] = true;
            let current       = this->aliases[current];
        }

        return current;
    }
}

View on GitHub (pinned to b7419de9cd)