{"record":{"id":"36c39dca66cfa469","repo":"twigphp/Twig","slug":"the-format-list-filter-requires-the-intllistformatter-class","errorCode":null,"errorMessage":"The \"format_list\" filter requires the \"IntlListFormatter\" class, which is available since PHP 8.5.","messagePattern":"The \"format_list\" filter requires the \"IntlListFormatter\" class, which is available since PHP 8\\.5\\.","errorType":"exception","errorClass":"Twig\\Error\\RuntimeError","httpStatus":null,"severity":"error","filePath":"extra/intl-extra/IntlExtension.php","lineNumber":451,"sourceCode":"        return $this->formatDateTime($env, $date, $dateFormat, 'none', $pattern, $timezone, $calendar, $locale);\n    }\n\n    /**\n     * @param \\DateTimeInterface|string|null  $date     A date or null to use the current time\n     * @param \\DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged\n     */\n    public function formatTime(Environment $env, $date, ?string $timeFormat = null, string $pattern = '', $timezone = null, ?string $calendar = null, ?string $locale = null): string\n    {\n        return $this->formatDateTime($env, $date, 'none', $timeFormat, $pattern, $timezone, $calendar, $locale);\n    }\n\n    /**\n     * @param array<string|\\Stringable> $strings A list of items to be joined into a formatted list\n     */\n    public function formatList(array $strings, string $type = 'and', string $width = 'wide', ?string $locale = null): string\n    {\n        if (!class_exists('IntlListFormatter')) {\n            throw new RuntimeError('The \"format_list\" filter requires the \"IntlListFormatter\" class, which is available since PHP 8.5.');\n        }\n\n        $formatter = $this->createListFormatter($locale, $type, $width);\n        if (false === $ret = $formatter->format($strings)) {\n            throw new RuntimeError(\\sprintf('Unable to format the given list: %s', $formatter->getErrorMessage()));\n        }\n\n        return $ret;\n    }\n\n    private function createDateFormatter(?string $locale, ?string $dateFormat, ?string $timeFormat, string $pattern, ?\\DateTimeZone $timezone, ?string $calendar): \\IntlDateFormatter\n    {\n        $dateFormats = self::availableDateFormats();\n\n        if (null !== $dateFormat && !isset($dateFormats[$dateFormat])) {\n            throw new RuntimeError(\\sprintf('The date format \"%s\" does not exist, known formats are: \"%s\".', $dateFormat, implode('\", \"', array_keys($dateFormats))));\n        }\n","sourceCodeStart":433,"sourceCodeEnd":469,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/extra/intl-extra/IntlExtension.php#L433-L469","documentation":"The format_list filter of IntlExtension formats an array of strings into a locale-aware list (e.g. 'A, B and C'). It relies on PHP's IntlListFormatter class, which only exists in PHP 8.5+ with the intl extension. If the class is missing, the extension throws this RuntimeError instead of failing later inside IntlListFormatter.","triggerScenarios":"Calling the format_list Twig filter (IntlExtension::formatList) when the IntlListFormatter class does not exist — i.e. running PHP < 8.5, or PHP without the ext-intl extension compiled/loaded.","commonSituations":"Deploying an app using format_list to an older PHP runtime (pre-8.5); a container or shared host with ext-intl not installed; running unit tests on a PHP version matrix where intl is skipped.","solutions":["Upgrade PHP to 8.5 or newer, since IntlListFormatter is only available since PHP 8.5","Install/enable the intl extension (ext-intl) for your PHP version if 8.5+ is already running","Guard usage with class_exists('IntlListFormatter') and fall back to manual joining (e.g. implode) until the runtime is updated","Remove or branch around the format_list filter in templates that must run on older PHP"],"exampleFix":"// before\n{{ items|format_list }}\n// after\n{% if class_exists('IntlListFormatter') %}\n  {{ items|format_list }}\n{% else %}\n  {{ items|join(', ') }}\n{% endif %}","handlingStrategy":"fallback","validationCode":"if (!class_exists('IntlListFormatter')) { throw new \\LogicException('format_list requires PHP 8.5+ with ext-intl; upgrade or use join().'); }","typeGuard":"function supportsFormatList(): bool { return \\class_exists('IntlListFormatter'); }","tryCatchPattern":"try { $out = $twig->render($tpl, $ctx); } catch (\\Twig\\Error\\RuntimeError $e) { if (str_contains($e->getMessage(), 'IntlListFormatter')) { $out = fallbackJoin($ctx); } else { throw $e; } }","preventionTips":["Pin PHP >= 8.5 with ext-intl in composer.json / CI matrix","Add a boot-time check that IntlListFormatter exists before templates render","Avoid format_list in templates shared with older runtimes"],"tags":["php","intl","twig","missing-dependency"],"backgroundTag":"missing-optional-dependency","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"}