{"record":{"id":"8fb0c17c6e4a052f","repo":"octobercms/october","slug":"value-cannot-be-of-type-array-for","errorCode":null,"errorMessage":"Value cannot be of type array for ","messagePattern":"Value cannot be of type array for ","errorType":"exception","errorClass":"SystemException","httpStatus":null,"severity":"error","filePath":"modules/dashboard/classes/ReportDimensionFilter.php","lineNumber":81,"sourceCode":"        $knownOperations = [\n            self::OPERATION_EQUALS,\n            self::OPERATION_MORE_OR_EQUALS,\n            self::OPERATION_LESS_OR_EQUALS,\n            self::OPERATION_MORE,\n            self::OPERATION_LESS,\n            self::OPERATION_STARTS_WITH,\n            self::OPERATION_STRING_INCLUDES,\n            self::OPERATION_ONE_OF\n        ];\n\n        if (!in_array($operation, $knownOperations)) {\n            throw new SystemException('Invalid filter operation. Supported types: ' . implode(', ', $knownOperations));\n        }\n\n        if ($operation === self::OPERATION_ONE_OF && !is_array($value)) {\n            throw new SystemException('Value must be of type array for ' . self::OPERATION_ONE_OF . ' operation.');\n        } elseif ($operation !== self::OPERATION_ONE_OF && is_array($value)) {\n            throw new SystemException('Value cannot be of type array for ' . $operation . ' operation.');\n        }\n\n        $this->dataAttributeType = $dataAttributeType;\n        $this->attributeName = $attributeName;\n        $this->operation = $operation;\n        $this->value = $value;\n    }\n\n    /**\n     * Get the data attribute type\n     *\n     * @return string\n     */\n    public function getDataAttributeType(): string\n    {\n        return $this->dataAttributeType;\n    }\n","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/dashboard/classes/ReportDimensionFilter.php#L63-L99","documentation":"All comparison operations except OPERATION_ONE_OF work on a single scalar value. The constructor throws when an array value is paired with any other operation, because the SQL builder cannot compare a column to an array.","triggerScenarios":"new ReportDimensionFilter(ReportDimensionFilter::ATTR_TYPE_DIMENSION, null, ReportDimensionFilter::OPERATION_MORE, [100, 200]); also switching an operation from one_of to '>' while keeping the array value.","commonSituations":"Front-ends that always submit arrays regardless of the chosen operator; generic filter builders that normalize all values to arrays.","solutions":["Submit a scalar for scalar operations — pick one element (e.g. min of the range) or change the operation to OPERATION_ONE_OF","Normalize payload values based on operation: keep arrays only for one_of","Validate value type against the operation before constructing the filter"],"exampleFix":"// before\n$filter = new ReportDimensionFilter(\n    ReportDimensionFilter::ATTR_TYPE_DIMENSION,\n    null,\n    ReportDimensionFilter::OPERATION_MORE,\n    $payload['value'] // ['min' => 100, 'max' => 200]\n);\n\n// after\n$filter = new ReportDimensionFilter(\n    ReportDimensionFilter::ATTR_TYPE_DIMENSION,\n    null,\n    ReportDimensionFilter::OPERATION_MORE,\n    (int) $payload['value']['min']\n);","handlingStrategy":"validation","validationCode":"if ($operation !== ReportDimensionFilter::OPERATION_ONE_OF && is_array($value)) {\n    if (count($value) === 1) {\n        $value = reset($value); // single-element array -> scalar\n    } else {\n        throw new InvalidArgumentException('Multiple values require the one_of operation');\n    }\n}\n$filter = new ReportDimensionFilter($type, $attribute, $operation, $value);","typeGuard":"function filterValueMatchesOperation(string $operation, mixed $value): bool\n{\n    return $operation === ReportDimensionFilter::OPERATION_ONE_OF\n        ? is_array($value)\n        : !is_array($value);\n}","tryCatchPattern":null,"preventionTips":["Send scalars for scalar comparisons and arrays only for one_of","When a user picks a range, either send two separate filters or switch to one_of over the allowed set","Normalize front-end payloads based on the selected operator"],"tags":["php","dashboard","report","filter","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}