Where are my annotations?! (Symfony 2.8)

Semantical Error?

Did you happen to see something like this while running your phpunit functional or integration tests?

[Semantical Error] The annotation "@Sensio\Bundle\FrameworkExtraBundle\Configuration\Route" ... does not exist, or could not be auto-loaded.

or

[Semantical Error] The annotation "@Symfony\Component\Validator\Constraints\NotBlank" ... does not exist, or could not be auto-loaded.

If so, you could be coming across an autoloader problem.

How do you fix this? Well, you want to autoload, of course.

How do I autoload?

I would assume you have a bootstrap file configured for php. All you have to do is point the loader to the correct vendor autoload.php file, register it, and you should be golden.

$loader = require '/../vendor/autoload.php'; // YMMV, this may be somewhere else for you.
Doctrine\Common\Annotations\AnnotationRegistry::registerLoader([$loader, 'loadClass']);

Leave a comment

Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Privacy Preferences
When you visit our website, it may store information through your browser from specific services, usually in form of cookies. Here you can change your privacy preferences. Please note that blocking some types of cookies may impact your experience on our website and the services we offer.