{"record":{"id":"1d7c834859fe2b67","repo":"twigphp/Twig","slug":"the-number-formatter-attribute-s-does-not-exist-known","errorCode":null,"errorMessage":"The number formatter attribute \"%s\" does not exist, known attributes are: \"%s\".","messagePattern":"The number formatter attribute \"(.+?)\" does not exist, known attributes are: \"(.+?)\"\\.","errorType":"exception","errorClass":"Twig\\Error\\RuntimeError","httpStatus":null,"severity":"error","filePath":"extra/intl-extra/IntlExtension.php","lineNumber":578,"sourceCode":"\n            foreach (self::NUMBER_SYMBOLS as $name => $const) {\n                $symbols[$name] = $this->numberFormatterPrototype->getSymbol($const);\n            }\n        }\n\n        ksort($attrs);\n        $hash = $locale.'|'.$style.'|'.json_encode($attrs).'|'.json_encode($textAttrs).'|'.json_encode($symbols);\n\n        if (!isset($this->numberFormatters[$hash])) {\n            if (\\count($this->numberFormatters) >= self::MAX_CACHED_FORMATTERS) {\n                array_shift($this->numberFormatters);\n            }\n            $this->numberFormatters[$hash] = new \\NumberFormatter($locale, self::NUMBER_STYLES[$style]);\n        }\n\n        foreach ($attrs as $name => $value) {\n            if (!isset(self::NUMBER_ATTRIBUTES[$name])) {\n                throw new RuntimeError(\\sprintf('The number formatter attribute \"%s\" does not exist, known attributes are: \"%s\".', $name, implode('\", \"', array_keys(self::NUMBER_ATTRIBUTES))));\n            }\n\n            if ('rounding_mode' === $name) {\n                if (!isset(self::NUMBER_ROUNDING_ATTRIBUTES[$value])) {\n                    throw new RuntimeError(\\sprintf('The number formatter rounding mode \"%s\" does not exist, known modes are: \"%s\".', $value, implode('\", \"', array_keys(self::NUMBER_ROUNDING_ATTRIBUTES))));\n                }\n\n                $value = self::NUMBER_ROUNDING_ATTRIBUTES[$value];\n            } elseif ('padding_position' === $name) {\n                if (!isset(self::NUMBER_PADDING_ATTRIBUTES[$value])) {\n                    throw new RuntimeError(\\sprintf('The number formatter padding position \"%s\" does not exist, known positions are: \"%s\".', $value, implode('\", \"', array_keys(self::NUMBER_PADDING_ATTRIBUTES))));\n                }\n\n                $value = self::NUMBER_PADDING_ATTRIBUTES[$value];\n            }\n\n            $this->numberFormatters[$hash]->setAttribute(self::NUMBER_ATTRIBUTES[$name], $value);\n        }","sourceCodeStart":560,"sourceCodeEnd":596,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/extra/intl-extra/IntlExtension.php#L560-L596","documentation":"createNumberFormatter validates each entry of the $attrs array against IntlExtension::NUMBER_ATTRIBUTES. An attribute name not present in that map throws this RuntimeError listing the recognized attribute names.","triggerScenarios":"Calling format_number or format_currency with attrs containing an unknown key — e.g. {'max_fraction_digits': 2} instead of 'fraction_digit'/'rounding_mode' style names supported by the extension.","commonSituations":"Guessing attribute names based on \\NumberFormatter PHP constants (MAX_FRACTION_DIGITS) instead of the extension's accepted string keys; config-driven attribute maps that were never validated.","solutions":["Use only attribute names listed in the error message (keys of NUMBER_ATTRIBUTES, e.g. 'fraction_digit')","Rename the attribute key in the attrs array to a known one","Validate attribute keys against NUMBER_ATTRIBUTES before calling the filter","Check the IntlExtension docs/tests for the exact accepted attribute strings"],"exampleFix":"// before\n{{ n|format_number(attrs={'max_fraction_digits': 2}) }}\n// after\n{{ n|format_number(attrs={'fraction_digit': 2}) }}","handlingStrategy":"validation","validationCode":"$bad = array_diff(array_keys($attrs), array_keys(IntlExtension::NUMBER_ATTRIBUTES)); if ($bad) { throw new \\InvalidArgumentException('Unknown attrs: '.implode(',', $bad)); }","typeGuard":"function hasKnownNumberAttrs(array $attrs): bool { return [] === array_diff(array_keys($attrs), array_keys(IntlExtension::NUMBER_ATTRIBUTES)); }","tryCatchPattern":"try { $out = $intl->formatNumber($n, $style, $attrs); } catch (\\Twig\\Error\\RuntimeError $e) { if (str_contains($e->getMessage(), 'attribute')) { $out = $intl->formatNumber($n, $style, []); } else { throw $e; } }","preventionTips":["Keep a local enum of allowed attribute keys","Validate attribute maps when loading config","Do not translate \\NumberFormatter constants to snake_case by guesswork"],"tags":["php","intl","number-formatting","invalid-argument"],"backgroundTag":"invalid-enum-value","analyzedSha":"a414c3a491defb5a60f2fc88ef79ff37c90010cd","analyzedAt":"2026-09-13T15:10:46.849Z","contentChangedAt":"2026-09-13T15:10:46.849Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}