explaingit

phpdocumentor/reflectiondocblock

9,387PHPAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

ReflectionDocBlock is a PHP library that parses PHPDoc comment blocks above functions and classes into queryable objects, making it easy to read summaries, descriptions, and tags like parameter types from code comments.

Mindmap

mindmap
  root((reflectiondocblock))
    What it does
      Parse PHPDoc comments
      Convert to objects
      Query tags and types
    Key concepts
      DocBlock format
      PHPDoc standard
      Summary and description
      Tags like param return
    API
      Factory create method
      Raw string or Reflection
      DocBlock object
    Use cases
      Custom annotations
      Doc generators
      Runtime type inspection
    Audience
      PHP framework authors
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Parse PHPDoc comments in your own PHP library to support custom annotations or extract type information at runtime.

USE CASE 2

Build a PHP documentation generator that reads structured code comments and exports them as structured data.

USE CASE 3

Inspect function parameter types and return values from DocBlocks without writing a custom comment parser.

Tech stack

PHPComposer

Getting it running

Difficulty · easy Time to first run · 5min
MIT license, use freely in any project, commercial or open-source, just keep the copyright notice.

In plain English

ReflectionDocBlock is a PHP library that reads and interprets DocBlocks, which are the structured comment blocks PHP developers place above functions, classes, and properties in their code. These comments follow a format called the PHPDoc standard, and they typically begin with a slash and two asterisks. The library parses those comment blocks and converts them into objects that code can inspect and query. If you are building a tool that needs to understand what a PHP function is supposed to do based on its comments, or if you want to support annotations in your own library, this component handles the parsing work for you. It is part of the phpDocumentor project, which is the standard documentation generator for PHP. Using it is fairly direct. You create a factory object and call its create method with either a raw comment string or a PHP reflection object that has a getDocComment method. The factory returns a DocBlock object. From that object you can retrieve the summary (the opening line of the comment), the full description, and any tags embedded in the comment such as types, parameters, or return values. The library is installed via Composer, the standard PHP package manager, with a single command. It carries an MIT license, which means it can be used freely in commercial and open-source projects alike. The README is short and covers only the basics of instantiation and querying. Additional examples are available in the repository's docs folder for anyone who needs to explore more advanced usage.

Copy-paste prompts

Prompt 1
Show me how to use ReflectionDocBlock to read the @param and @return tags from a PHP function's DocBlock and print them as a plain-English summary.
Prompt 2
I'm building a PHP framework that supports custom @Route annotations in DocBlocks. Walk me through using ReflectionDocBlock's factory to parse those tags from controller methods.
Prompt 3
How do I install ReflectionDocBlock via Composer and write a script that accepts a PHP class name, reflects all its methods, and prints each method's DocBlock summary and parameter list?
Prompt 4
Use ReflectionDocBlock to validate that all public methods in a PHP class have a non-empty DocBlock summary and at least one @param tag, return a list of non-compliant methods.
Prompt 5
Explain the difference between passing a raw DocBlock string vs a PHP ReflectionMethod object to ReflectionDocBlock's factory, and when you'd use each approach.
Open on GitHub → Explain another repo

← phpdocumentor on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.