{"record":{"id":"97312b7c48202c3b","repo":"yiisoft/yii2","slug":"operator-operator-requires-two-operands","errorCode":null,"errorMessage":"Operator '$operator' requires two operands.","messagePattern":"Operator '\\$operator' requires two operands\\.","errorType":"exception","errorClass":"yii\\base\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"framework/db/conditions/InCondition.php","lineNumber":86,"sourceCode":"    {\n        return $this->column;\n    }\n\n    /**\n     * @return ExpressionInterface[]|string[]|int[]\n     */\n    public function getValues()\n    {\n        return $this->values;\n    }\n    /**\n     * {@inheritdoc}\n     * @throws InvalidArgumentException if wrong number of operands have been given.\n     */\n    public static function fromArrayDefinition($operator, $operands)\n    {\n        if (!isset($operands[0], $operands[1])) {\n            throw new InvalidArgumentException(\"Operator '$operator' requires two operands.\");\n        }\n\n        return new static($operands[0], $operator, $operands[1]);\n    }\n}\n","sourceCodeStart":68,"sourceCodeEnd":92,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/db/conditions/InCondition.php#L68-L92","documentation":"yii\\db\\conditions\\InCondition::fromArrayDefinition() (framework/db/conditions/InCondition.php:86) validates IN / NOT IN conditions in operator format and requires both operands — the column (or column list) and the values — to be set. The isset() check means ['in','col',null] throws exactly like ['in','col']. An empty values array is accepted (it builds a harmless false condition); a missing or null one is not.","triggerScenarios":"->where(['in','id']) with the values omitted; ['not in','status',null] when the id/status list is null; building ['in',$column,$ids] from request data where $ids never arrived.","commonSituations":"REST endpoints filtering by an optional id list (?ids=) that arrives empty or null; andFilterWhere(['in','id',null]) does NOT save you — filterCondition (framework/db/QueryTrait.php:278-281) only checks operand 1 (the column), so the null values operand survives and throws here; passing null instead of [] when nothing was selected.","solutions":["Pass both operands: ['in', 'id', $ids]","If the list is optional, skip the condition for null/empty input: if (!empty($ids)) { ... } — andFilterWhere only sanitizes the first operand","Coalesce to an empty array: ['in', 'id', $ids ?? []] builds a false condition instead of throwing"],"exampleFix":"// before\n$query->andWhere(['in', 'id', $ids]); // $ids === null -> Operator 'IN' requires two operands.\n\n// after\nif (!empty($ids)) {\n    $query->andWhere(['in', 'id', $ids]);\n} // or: $query->andWhere(['in', 'id', $ids ?? []]);","handlingStrategy":"validation","validationCode":"// Normalize an optional id list before building the condition\n$ids = is_array($ids)\n    ? array_values(array_filter($ids, static fn ($v) => $v !== null && $v !== ''))\n    : null;\n\nif (!empty($ids)) {\n    $query->andWhere(['in', 'id', $ids]);\n} // else: omit the condition entirely","typeGuard":null,"tryCatchPattern":"try {\n    $rows = $query->all();\n} catch (\\yii\\base\\InvalidArgumentException $e) {\n    \\Yii::warning('Malformed IN condition: ' . $e->getMessage(), __METHOD__);\n    $rows = [];\n}","preventionTips":["Do not rely on andFilterWhere to sanitize IN values — filterCondition (framework/db/QueryTrait.php:278) only checks operand 1 (the column)","Coalesce optional lists: ['in','id',$ids ?? []] instead of passing null","Validate array-typed request params (ids[]) at the controller boundary"],"tags":["yii2","database","query-builder","in-condition","where-condition","validation"],"backgroundTag":"malformed-query-condition","analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}