symfony/routing · critical · LogicException

The Tokenizer extension is required for the routing…

Error message

The Tokenizer extension is required for the routing attribute loader.

What it means

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.

Solutions

  1. Install/enable the tokenizer extension: docker-php-ext-install tokenizer or apk add php83-tokenizer / apt install php-tokenizer
  2. Verify with php -m | grep tokenizer
  3. Rebuild the PHP image including ext-tokenizer

Example fix

// Dockerfile before
FROM php:8.3-cli-alpine
// after
FROM php:8.3-cli-alpine
RUN docker-php-ext-install tokenizer
Defensive patterns

Strategy: type-guard

Validate before calling

if (!function_exists('token_get_all')) { throw new \RuntimeException('Enable ext-tokenizer before using attribute routing'); }

Type guard

function tokenizerAvailable(): bool { return function_exists('token_get_all'); }

Try / catch

try { $loader = new AttributeFileLoader($locator, $classLoader); } catch (\LogicException $e) { /* ext-tokenizer missing — install/enable it */ }

Prevention

When it happens

Trigger: 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).

Common situations: Alpine/minimal PHP Docker images without ext-tokenizer; switching hosting providers; container images optimized by removing 'default' extensions.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.


AI-assisted analysis of symfony/routing@83fa223250 (2026-09-14). Data as JSON: /api/errors/98baea7b86f97294. Report an issue: GitHub.

Appendix: source

Thrown at Loader/AttributeFileLoader.php:33

use Symfony\Component\Config\Loader\FileLoader;
use Symfony\Component\Config\Resource\ReflectionClassResource;
use Symfony\Component\Routing\RouteCollection;

/**
 * AttributeFileLoader loads routing information from attributes set
 * on a PHP class and its methods.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 * @author Alexandre Daubois <alex.daubois@gmail.com>
 */
class AttributeFileLoader extends FileLoader
{
    public function __construct(
        FileLocatorInterface $locator,
        protected AttributeClassLoader $loader,
    ) {
        if (!\function_exists('token_get_all')) {
            throw new \LogicException('The Tokenizer extension is required for the routing attribute loader.');
        }

        parent::__construct($locator);
    }

    /**
     * Loads from attributes from a file.
     *
     * @throws \InvalidArgumentException When the file does not exist or its routes cannot be parsed
     */
    public function load(mixed $file, ?string $type = null): ?RouteCollection
    {
        $path = $this->locator->locate($file);

        $collection = new RouteCollection();
        if ($class = $this->findClass($path)) {
            $refl = new \ReflectionClass($class);
            if ($refl->isAbstract()) {

View on GitHub (pinned to 83fa223250)