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.
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 22Common 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
- Run
php -lon the file named in the error to confirm the parse/type issue. - Align the method signature with the parent or interface it overrides.
- Re-run
cache:clearto confirm warmup succeeds.
php -l src/Repository/UserRepository.php
APP_ENV=test php bin/console cache:clearPin the dependency that changed the base signature
If a version bump introduced the incompatibility, pin to a compatible release while you adapt the override.
composer require "doctrine/orm:^2.19" --no-update
composer update doctrine/ormHow to prevent it
- Run
bin/console lint:containerand 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.