doctrine/annotations
Doctrine Annotations parses and reads docblock annotations for PHP projects. Considered feature complete since PHP 8 attributes are the native replacement; this package now focuses on bugfixes and security fixes. Documentation available on doctrine-project.org.
@Route("/path")) — not PHP 8+ attributes. Given the deprecation warning in the README, avoid using it in new projects unless maintaining legacy code.composer require doctrine/annotationsAnnotationReader to parse docblocks:
use Doctrine\Common\Annotations\AnnotationReader;
$reader = new AnnotationReader();
$reader->getClassAnnotations(new ReflectionClass(MyClass::class));
@Entity) with public properties or constructor parameters. They must live in a PSR-4 autoloading namespace (e.g., App\Annotations).CachedReader or PsrCachedReader (preferred in v2+) with a PSR-6/PSR-16 cache to avoid re-parsing docblocks on each request:
$reader = new CachedReader(
new AnnotationReader(),
new SymfonyComponentCacheAdapterArrayAdapter()
);
annotations config in config/packages/framework.yaml (enable enabled: true or null for auto-detect).AnnotationReader (e.g., to support namespaced aliases or custom fallbacks).eval() pitfalls: The parser uses eval() internally for parsing — avoid dynamic docblocks with user input to prevent RCE risks.php bin/console cache:pool:clear annotations in Symfony) — stale caches cause silent failures.@phpstan, @psalm, @readonly, @noinspection are ignored by default. Add new reserved names via AnnotationReader::addGlobalIgnoredName().ReflectionMethod::getDocComment() to verify docblock formatting before parsing. Malformed docblocks (e.g., missing @) cause ReflectionException.How can I help you explore Laravel packages today?