nikic/PHP-Parser · error · LogicException

Variable name must be string or Expr

Error message

Variable name must be string or Expr

What it means

Error "Variable name must be string or Expr" thrown in nikic/PHP-Parser.

Source

Thrown at lib/PhpParser/BuilderFactory.php:226

    }

    /**
     * Creates node a for a literal value.
     *
     * @param Expr|bool|null|int|float|string|array|\UnitEnum $value $value
     */
    public function val($value): Expr {
        return BuilderHelpers::normalizeValue($value);
    }

    /**
     * Creates variable node.
     *
     * @param string|Expr $name Name
     */
    public function var($name): Expr\Variable {
        if (!\is_string($name) && !$name instanceof Expr) {
            throw new \LogicException('Variable name must be string or Expr');
        }

        return new Expr\Variable($name);
    }

    /**
     * Normalizes an argument list.
     *
     * Creates Arg nodes for all arguments and converts literal values to expressions.
     *
     * @param array $args List of arguments to normalize
     *
     * @return list<Arg>
     */
    public function args(array $args): array {
        $normalizedArgs = [];
        foreach ($args as $key => $arg) {
            if (!($arg instanceof Arg)) {

View on GitHub (pinned to fbd47f7ebc)

When it happens

Trigger: Thrown at lib/PhpParser/BuilderFactory.php:226 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/3f66f205d5dfb9a9. Report an issue: GitHub.