{"record":{"id":"b3503a216a9c390b","repo":"PHPOffice/PhpSpreadsheet","slug":"invalid-dynamic-rule-type-dynamicruletype","errorCode":null,"errorMessage":"invalid dynamic rule type $dynamicRuleType","messagePattern":"invalid dynamic rule type \\$dynamicRuleType","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Worksheet/AutoFilter.php","lineNumber":737,"sourceCode":"    private static function dynamicYesterday(): array\n    {\n        $maxval = new DateTime();\n        $maxval->setTime(0, 0, 0);\n        $val = clone $maxval;\n        $val->modify('-1 day');\n\n        return [$val, $maxval];\n    }\n\n    /**\n     * Convert a dynamic rule daterange to a custom filter range expression for ease of calculation.\n     *\n     * @return mixed[]\n     */\n    private function dynamicFilterDateRange(string $dynamicRuleType, AutoFilter\\Column &$filterColumn): array\n    {\n        $ruleValues = [];\n        $callBack = [__CLASS__, self::DATE_FUNCTIONS[$dynamicRuleType] ?? throw new Exception(\"invalid dynamic rule type $dynamicRuleType\")];\n        //    Calculate start/end dates for the required date range based on current date\n        //    Val is lowest permitted value.\n        //    Maxval is greater than highest permitted value\n        [$val, $maxval] = $callBack();\n        $val = Date::dateTimeToExcel($val);\n        $maxval = Date::dateTimeToExcel($maxval);\n\n        //    Set the filter column rule attributes ready for writing\n        $filterColumn->setAttributes(['val' => $val, 'maxVal' => $maxval]);\n\n        //    Set the rules for identifying rows for hide/show\n        $ruleValues[] = ['operator' => Rule::AUTOFILTER_COLUMN_RULE_GREATERTHANOREQUAL, 'value' => $val];\n        $ruleValues[] = ['operator' => Rule::AUTOFILTER_COLUMN_RULE_LESSTHAN, 'value' => $maxval];\n\n        return ['method' => 'filterTestInCustomDataSet', 'arguments' => ['filterRules' => $ruleValues, 'join' => AutoFilter\\Column::AUTOFILTER_COLUMN_JOIN_AND]];\n    }\n\n    /**","sourceCodeStart":719,"sourceCodeEnd":755,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Worksheet/AutoFilter.php#L719-L755","documentation":"When evaluating a dynamicFilter rule, AutoFilter::dynamicFilterDateRange() looks the rule value up in its private DATE_FUNCTIONS map, which contains only the 17 date-window types (yesterday, today, tomorrow, yearToDate, this/last/next Year|Quarter|Month|Week). Any other value reaching this method throws. Note that aboveAverage/belowAverage and M1-M12/Q1-Q4 codes are valid groupings but are not in this map, so they must not reach the date-range path.","triggerScenarios":"Building a Rule with AUTOFILTER_RULETYPE_DYNAMICFILTER and a made-up value like 'lastFortnight', then running $autoFilter->showHideRows(); also loaded files whose dynamicFilter val attribute does not match a known token.","commonSituations":"Hand-constructed dynamic rules with invented strings; user input used directly as a dynamic filter value; malformed/untrusted Xlsx files.","solutions":["Use the Rule::AUTOFILTER_RULETYPE_DYNAMIC_* constants (e.g. Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTMONTH) instead of raw strings","Validate the value against the 17 known date-window tokens before applying or evaluating the filter","Reject or sanitize dynamicFilter values coming from untrusted files before re-saving/evaluating"],"exampleFix":"// before\n$rule->setRuleType(Rule::AUTOFILTER_RULETYPE_DYNAMICFILTER)->setValue('lastFortnight');\n\n// after\n$rule->setRuleType(Rule::AUTOFILTER_RULETYPE_DYNAMICFILTER)->setValue(Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTWEEK);","handlingStrategy":"validation","validationCode":"$dateWindowTypes = [\n    'yesterday', 'today', 'tomorrow', 'yearToDate',\n    'thisYear', 'thisQuarter', 'thisMonth', 'thisWeek',\n    'lastYear', 'lastQuarter', 'lastMonth', 'lastWeek',\n    'nextYear', 'nextQuarter', 'nextMonth', 'nextWeek',\n];\nif (!in_array($dynamicValue, $dateWindowTypes, true)) {\n    throw new InvalidArgumentException(\"Unknown dynamic filter '$dynamicValue'\");\n}","typeGuard":"function isDateWindowDynamicType(string $value): bool\n{\n    return in_array($value, [\n        'yesterday', 'today', 'tomorrow', 'yearToDate',\n        'thisYear', 'thisQuarter', 'thisMonth', 'thisWeek',\n        'lastYear', 'lastQuarter', 'lastMonth', 'lastWeek',\n        'nextYear', 'nextQuarter', 'nextMonth', 'nextWeek',\n    ], true);\n}","tryCatchPattern":"try {\n    $autoFilter->showHideRows();\n} catch (\\PhpOffice\\PhpSpreadsheet\\Exception $e) {\n    // a dynamic rule value is not in the date-window map: strip dynamic rules and re-evaluate\n}","preventionTips":["Always set dynamic values via Rule::AUTOFILTER_RULETYPE_DYNAMIC_* constants","Validate untrusted filter definitions before applying them to a worksheet"],"tags":["autofilter","dynamic-filter","enum","validation","phpspreadsheet"],"backgroundTag":"invalid-enum-value","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}