{"record":{"id":"d69b22136c0e97d4","repo":"PHPOffice/PhpSpreadsheet","slug":"invalid-rule-value-for-column-autofilter-rule","errorCode":null,"errorMessage":"Invalid rule value for column AutoFilter Rule.","messagePattern":"Invalid rule value for column AutoFilter Rule\\.","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Worksheet/AutoFilter/Column/Rule.php","lineNumber":274,"sourceCode":"     * @return $this\n     */\n    public function setValue($value): static\n    {\n        $this->setEvaluatedFalse();\n        if (is_array($value)) {\n            $grouping = -1;\n            foreach ($value as $key => $v) {\n                //    Validate array entries\n                if (!in_array($key, self::DATE_TIME_GROUPS)) {\n                    //    Remove any invalid entries from the value array\n                    unset($value[$key]);\n                } else {\n                    //    Work out what the dateTime grouping will be\n                    $grouping = max($grouping, array_search($key, self::DATE_TIME_GROUPS));\n                }\n            }\n            if (count($value) == 0) {\n                throw new PhpSpreadsheetException('Invalid rule value for column AutoFilter Rule.');\n            }\n            //    Set the dateTime grouping that we've anticipated\n            $this->setGrouping(self::DATE_TIME_GROUPS[$grouping]); // @phpstan-ignore offsetAccess.notFound (no idea what phpstan is complaining about)\n        }\n        $this->value = $value;\n\n        return $this;\n    }\n\n    /**\n     * Get AutoFilter Rule Operator.\n     */\n    public function getOperator(): string\n    {\n        return $this->operator;\n    }\n\n    /**","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Worksheet/AutoFilter/Column/Rule.php#L256-L292","documentation":"When a rule value is set as an array (a dateGroupItem), every key must be one of year, month, day, hour, minute, second. Invalid keys are silently stripped; if none survive, the value array is empty and the rule is rejected as invalid. Key matching is case-sensitive.","triggerScenarios":"->setValue(['Year' => 2024]) (wrong casing), ->setValue(['date' => '2024-01-01']) or ->setValue([]) — all leave zero valid keys after stripping.","commonSituations":"Passing complete dates/timestamps instead of date components; wrong key casing from array keys generated by array_change_key_case-sensitive code; empty arrays from failed date parsing.","solutions":["Use the exact key set year/month/day/hour/minute/second with integer components, e.g. ['year' => 2024, 'month' => 1, 'day' => 15]","Validate array_keys($value) against the allowed list before setValue()","For plain value filters, pass a scalar instead of an array"],"exampleFix":"// before\n$rule->setValue(['date' => '2024-01-15']);\n\n// after\n$rule->setValue(['year' => 2024, 'month' => 1, 'day' => 15]);","handlingStrategy":"validation","validationCode":"$allowedKeys = ['year', 'month', 'day', 'hour', 'minute', 'second'];\nif (is_array($value) && array_diff(array_keys($value), $allowedKeys) !== []) {\n    throw new InvalidArgumentException('dateGroup keys must be year/month/day/hour/minute/second');\n}\n$rule->setValue($value);","typeGuard":"function isDateGroupValue(array $value): bool\n{\n    $allowed = ['year', 'month', 'day', 'hour', 'minute', 'second'];\n\n    return array_diff(array_keys($value), $allowed) === [] && $value !== [];\n}","tryCatchPattern":"try {\n    $rule->setValue($value);\n} catch (\\PhpOffice\\PhpSpreadsheet\\Exception $e) {\n    // not a valid dateGroup: fall back to a scalar equality filter\n    $rule->setValue(implode('-', $value));\n}","preventionTips":["Build dateGroup arrays from DateTime::format() fields with exact lowercase keys","Never pass complete date strings as the rule value"],"tags":["autofilter","date-group","filter-value","validation","phpspreadsheet"],"backgroundTag":"invalid-filter-value","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}