symfony/symfony · error · LogicException

You cannot use the "Symfony\Bridge\Doctrine\Form\DoctrineOrm

Error message

You cannot use the "Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser" class as the "symfony/form" package is not installed. Try running "composer require symfony/form".

What it means

Thrown at class-load time when DoctrineOrmTypeGuesser.php is autoloaded but the symfony/form package (FormTypeGuesserInterface) is not installed (DoctrineOrmTypeGuesser.php:39-41). The guesser implements FormTypeGuesserInterface, so without the Form component the class cannot exist; Symfony fails fast with an actionable message.

Source

Thrown at src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php:40

use Doctrine\Persistence\Proxy;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\DateIntervalType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TimeType;
use Symfony\Component\Form\FormTypeGuesserInterface;
use Symfony\Component\Form\Guess\Guess;
use Symfony\Component\Form\Guess\TypeGuess;
use Symfony\Component\Form\Guess\ValueGuess;

if (!interface_exists(FormTypeGuesserInterface::class)) {
    throw new \LogicException('You cannot use the "Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser" class as the "symfony/form" package is not installed. Try running "composer require symfony/form".');
}

class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
{
    private array $cache = [];

    public function __construct(
        protected ManagerRegistry $registry,
    ) {
    }

    public function guessType(string $class, string $property): ?TypeGuess
    {
        if (!$ret = $this->getMetadata($class)) {
            return new TypeGuess(TextType::class, [], Guess::LOW_CONFIDENCE);
        }

        [$metadata, $name] = $ret;

View on GitHub (pinned to 698e28026c)

Solutions

  1. Install the Form component: 'composer require symfony/form'.
  2. If you intentionally do not use forms, remove the DoctrineOrmTypeGuesser service/tag from your config and any code referencing it.
  3. Clear the cache after changing dependencies so stale container refs don't autoload the class.

Example fix

# before: symfony/form absent, services.yaml references doctrine.orm_type_guesser
composer show symfony/form   # not installed -> LogicException on boot

# after
composer require symfony/form
# or, if forms are unused, remove the DoctrineOrmTypeGuesser service from config
Defensive patterns

Strategy: validation

Validate before calling

use Symfony\Component\Form\FormTypeGuesserInterface;
if (!interface_exists(FormTypeGuesserInterface::class)) {
    throw new \LogicException('symfony/form missing — cannot use DoctrineOrmTypeGuesser');
}

Type guard

function formComponentInstalled(): bool {
    return interface_exists(\Symfony\Component\Form\FormTypeGuesserInterface::class);
}

Try / catch

// Avoid referencing the class when the component is absent
if (class_exists(\Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser::class, false)) { /* safe */ }

Prevention

When it happens

Trigger: Autoloading Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser (e.g. it is referenced in service configuration, a bundle autoconfig, or code) while symfony/form is not in composer.json. The `if (!interface_exists(FormTypeGuesserInterface::class))` guard fires at file load.

Common situations: Installing symfony/doctrine-bridge without symfony/form; an API-only skeleton that dropped form but left the guesser wired in services.yaml; DoctrineBundle default config referencing the guesser.

Related errors


AI-assisted analysis of symfony/symfony@698e28026c (2026-08-06). Data as JSON: /api/errors/82f9dab6908ed225. Report an issue: GitHub.