nikic/PHP-Parser · error · LogicException

Name must be a string or an instance of Node\Name

Error message

Name must be a string or an instance of Node\Name

What it means

Error "Name must be a string or an instance of Node\Name" thrown in nikic/PHP-Parser.

Source

Thrown at lib/PhpParser/BuilderHelpers.php:127

        }

        if (is_string($name)) {
            if (!$name) {
                throw new \LogicException('Name cannot be empty');
            }

            if ($name[0] === '\\') {
                return new Name\FullyQualified(substr($name, 1));
            }

            if (0 === strpos($name, 'namespace\\')) {
                return new Name\Relative(substr($name, strlen('namespace\\')));
            }

            return new Name($name);
        }

        throw new \LogicException('Name must be a string or an instance of Node\Name');
    }

    /**
     * Normalizes a name: Converts string names to Name nodes, while also allowing expressions.
     *
     * @param Expr|Name|string $name The name to normalize
     *
     * @return Name|Expr The normalized name or expression
     */
    public static function normalizeNameOrExpr($name) {
        if ($name instanceof Expr) {
            return $name;
        }

        if (!is_string($name) && !($name instanceof Name)) {
            throw new \LogicException(
                'Name must be a string or an instance of Node\Name or Node\Expr'
            );

View on GitHub (pinned to fbd47f7ebc)

When it happens

Trigger: Thrown at lib/PhpParser/BuilderHelpers.php:127 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of nikic/PHP-Parser@fbd47f7ebc (2026-08-17). Data as JSON: /api/errors/3ec5847fd69f4395. Report an issue: GitHub.