Skip to content
Latchkey

Symfony cache:clear "Compile Error" during container warmup in CI

When cache:clear warms the container it loads your service classes. A Compile Error here is a real PHP syntax or type error in a class the container references, surfaced only because warmup instantiates or reflects over it.

What this error means

bin/console cache:clear fails with "PHP Fatal error: Compile Error: ..." or "Fatal error: Type ... must be compatible with ...", pointing at one of your source files.

Symfony
PHP Fatal error:  Compile Error: Declaration of App\Repository\UserRepository::find($id)
must be compatible with Doctrine\ORM\EntityRepository::find($id, $lockMode = null, $lockVersion = null)
in /app/src/Repository/UserRepository.php on line 22

Common causes

A signature or type incompatibility

An overridden method or return type is incompatible with its parent or interface. PHP raises a compile error the moment the class is loaded during warmup.

A dependency version bump changed a base signature

CI resolved a newer Doctrine or Symfony version whose base method signature differs from what your subclass declared.

How to fix it

Reproduce with a straight PHP lint and fix the signature

  1. Run php -l on the file named in the error to confirm the parse/type issue.
  2. Align the method signature with the parent or interface it overrides.
  3. Re-run cache:clear to confirm warmup succeeds.
Terminal
php -l src/Repository/UserRepository.php
APP_ENV=test php bin/console cache:clear

Pin the dependency that changed the base signature

If a version bump introduced the incompatibility, pin to a compatible release while you adapt the override.

Terminal
composer require "doctrine/orm:^2.19" --no-update
composer update doctrine/orm

How to prevent it

  • Run bin/console lint:container and warm the cache in CI to catch compile errors early.
  • Keep overridden signatures in sync with library base classes.
  • Commit a lockfile so CI does not silently pull an incompatible version.

Frequently asked questions

What causes ""Compile Error" during cache:clear"?
An overridden method or return type is incompatible with its parent or interface. PHP raises a compile error the moment the class is loaded during warmup.
How do I fix "Compile Error" during cache:clear?
Reproduce with a straight PHP lint and fix the signature

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card