gitmyhub

annotations

PHP ★ 6.7k updated 6mo ago

Annotations Docblock Parser

Doctrine Annotations is a PHP library that reads special tags written inside code comments (called docblocks) and turns them into structured data that applications can act on. For example, a developer might write a tag like @Route("/homepage") in a comment above a function, and this library parses that tag so a web framework knows to connect that URL to that function. The idea is to put configuration directly alongside the code it describes rather than in separate files.

The library was originally part of Doctrine Common, a set of shared utilities used across the Doctrine database toolkit for PHP. It was extracted into its own package so other projects could use the annotation parsing feature independently.

The README includes an important note for anyone considering adopting this library: PHP 8 added native support for a similar concept called attributes, which accomplish the same goal through built-in language syntax rather than parsed comments. The Doctrine team considers this library feature-complete and recommends that new projects use PHP attributes instead. Libraries that currently depend on Doctrine Annotations are encouraged to add attribute-based alternatives for their users.

For existing projects that already use it, the library will continue to receive security and bug fixes, but no new features are planned. Full documentation is on the Doctrine project website.