yiisoft/yii2 · error · yii\base\InvalidArgumentException

Expression of class {} can not be built in {}

Error message

Expression of class {} can not be built in {}

What it means

Error "Expression of class {} can not be built in {}" thrown in yiisoft/yii2.

Source

Thrown at framework/db/QueryBuilder.php:316

     * @return ExpressionBuilderInterface
     * @throws InvalidArgumentException when $expression building is not supported by this QueryBuilder.
     * @since 2.0.14
     * @see expressionBuilders
     */
    public function getExpressionBuilder(ExpressionInterface $expression)
    {
        $className = get_class($expression);

        if (!isset($this->expressionBuilders[$className])) {
            foreach (array_reverse($this->expressionBuilders) as $expressionClass => $builderClass) {
                if (is_subclass_of($expression, $expressionClass)) {
                    $this->expressionBuilders[$className] = $builderClass;
                    break;
                }
            }

            if (!isset($this->expressionBuilders[$className])) {
                throw new InvalidArgumentException('Expression of class ' . $className . ' can not be built in ' . get_class($this));
            }
        }

        if ($this->expressionBuilders[$className] === __CLASS__) {
            /** @var $this&ExpressionBuilderInterface $result */
            $result = $this;
            return $result;
        }

        if (!is_object($this->expressionBuilders[$className])) {
            $this->expressionBuilders[$className] = new $this->expressionBuilders[$className]($this);
        }

        return $this->expressionBuilders[$className];
    }

    /**
     * Creates an INSERT SQL statement.

View on GitHub (pinned to 66f00d18a2)

When it happens

Trigger: Thrown at framework/db/QueryBuilder.php:316 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of yiisoft/yii2@66f00d18a2 (2026-08-17). Data as JSON: /api/errors/a95cfb1527851a0e. Report an issue: GitHub.