phpdocumentor / reflection-docblock
With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.
Package info
github.com/phpDocumentor/ReflectionDocBlock
pkg:composer/phpdocumentor/reflection-docblock
Requires
- php: ^7.4 || ^8.0
- ext-filter: *
- doctrine/deprecations: ^1.1
- phpdocumentor/reflection-common: ^2.2
- phpdocumentor/type-resolver: ^2.0
- phpstan/phpdoc-parser: ^2.0
- webmozart/assert: ^1.9.1 || ^2
Requires (Dev)
- mockery/mockery: ~1.3.5 || ~1.6.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.8
- phpstan/phpstan-mockery: ^1.1
- phpstan/phpstan-webmozart-assert: ^1.2
- phpunit/phpunit: ^9.5
- psalm/phar: ^5.26
- shipmonk/dead-code-detector: ^0.5.1
This package is auto-updated.
Last update: 2026-05-18 21:26:55 UTC
README
ReflectionDocBlock
Introduction
The ReflectionDocBlock component of phpDocumentor provides a DocBlock parser that is 100% compatible with the PHPDoc standard.
With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.
Installation
composer require phpdocumentor/reflection-docblock
Usage
In order to parse the DocBlock one needs a DocBlockFactory that can be
instantiated using its createInstance factory method like this:
$factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
Then we can use the create method of the factory to interpret the DocBlock.
Please note that it is also possible to provide a class that has the
getDocComment() method, such as an object of type ReflectionClass, the
create method will read that if it exists.
$docComment = <<<DOCCOMMENT /** * This is an example of a summary. * * This is a Description. A Summary and Description are separated by either * two subsequent newlines (thus a whiteline in between as can be seen in this * example), or when the Summary ends with a dot (`.`) and some form of * whitespace. */ DOCCOMMENT; $docblock = $factory->create($docComment);
The create method will yield an object of type \phpDocumentor\Reflection\DocBlock
whose methods can be queried:
// Contains the summary for this DocBlock $summary = $docblock->getSummary(); // Contains \phpDocumentor\Reflection\DocBlock\Description object $description = $docblock->getDescription(); // You can either cast it to string $description = (string) $docblock->getDescription(); // Or use the render method to get a string representation of the Description. $description = $docblock->getDescription()->render();
For more examples it would be best to review the scripts in the
/docs/examplesfolder.