{"record":{"id":"98baea7b86f97294","repo":"symfony/routing","slug":"the-tokenizer-extension-is-required-for-the-routing","errorCode":null,"errorMessage":"The Tokenizer extension is required for the routing attribute loader.","messagePattern":"The Tokenizer extension is required for the routing attribute loader\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"critical","filePath":"Loader/AttributeFileLoader.php","lineNumber":33,"sourceCode":"use Symfony\\Component\\Config\\Loader\\FileLoader;\nuse Symfony\\Component\\Config\\Resource\\ReflectionClassResource;\nuse Symfony\\Component\\Routing\\RouteCollection;\n\n/**\n * AttributeFileLoader loads routing information from attributes set\n * on a PHP class and its methods.\n *\n * @author Fabien Potencier <fabien@symfony.com>\n * @author Alexandre Daubois <alex.daubois@gmail.com>\n */\nclass AttributeFileLoader extends FileLoader\n{\n    public function __construct(\n        FileLocatorInterface $locator,\n        protected AttributeClassLoader $loader,\n    ) {\n        if (!\\function_exists('token_get_all')) {\n            throw new \\LogicException('The Tokenizer extension is required for the routing attribute loader.');\n        }\n\n        parent::__construct($locator);\n    }\n\n    /**\n     * Loads from attributes from a file.\n     *\n     * @throws \\InvalidArgumentException When the file does not exist or its routes cannot be parsed\n     */\n    public function load(mixed $file, ?string $type = null): ?RouteCollection\n    {\n        $path = $this->locator->locate($file);\n\n        $collection = new RouteCollection();\n        if ($class = $this->findClass($path)) {\n            $refl = new \\ReflectionClass($class);\n            if ($refl->isAbstract()) {","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/symfony/routing/blob/83fa223250b50f4f018c011e101c330e65ac63cc/Loader/AttributeFileLoader.php#L15-L51","documentation":"AttributeFileLoader parses PHP files with token_get_all(), which requires the ext-tokenizer PHP extension. If the function token_get_all does not exist (tokenizer not compiled/enabled), the constructor throws LogicException immediately.","triggerScenarios":"Loading attribute-based routes with a PHP build that lacks the tokenizer extension (e.g. minimal Docker images, some shared hosts, PHP compiled with --disable-tokenizer).","commonSituations":"Alpine/minimal PHP Docker images without ext-tokenizer; switching hosting providers; container images optimized by removing 'default' extensions.","solutions":["Install/enable the tokenizer extension: docker-php-ext-install tokenizer or apk add php83-tokenizer / apt install php-tokenizer","Verify with php -m | grep tokenizer","Rebuild the PHP image including ext-tokenizer"],"exampleFix":"// Dockerfile before\nFROM php:8.3-cli-alpine\n// after\nFROM php:8.3-cli-alpine\nRUN docker-php-ext-install tokenizer","handlingStrategy":"type-guard","validationCode":"if (!function_exists('token_get_all')) { throw new \\RuntimeException('Enable ext-tokenizer before using attribute routing'); }","typeGuard":"function tokenizerAvailable(): bool { return function_exists('token_get_all'); }","tryCatchPattern":"try { $loader = new AttributeFileLoader($locator, $classLoader); } catch (\\LogicException $e) { /* ext-tokenizer missing — install/enable it */ }","preventionTips":["Pin ext-tokenizer in composer.json platform requirements or Dockerfile","Run php -m in CI to assert required extensions","Use the same PHP base image locally and in production"],"tags":["php-extension","environment","tokenizer"],"backgroundTag":"missing-env-var","analyzedSha":"83fa223250b50f4f018c011e101c330e65ac63cc","analyzedAt":"2026-09-14T03:19:46.280Z","contentChangedAt":"2026-09-14T03:19:46.280Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}