doc command displays documentation for PHP functions, classes, methods, properties, and constants. It extracts information from docblocks and the PHP manual.
Syntax
Aliases
rtfm(Read The Fine Manual)man(Manual pages)
Arguments
Function, class, instance, constant, method, or property to document
Options
Alias:
-aShow documentation for superclasses as well as the current class. Includes parent classes, interfaces, and traits.Download and install the latest PHP manual. Optionally specify a language code (e.g.,
fr, de, es).If no language is specified, uses the current language or defaults to English.Usage Examples
Documenting Functions
- Output
Documenting Classes
Documenting Methods
Documenting Instance Methods
-> operator.
Documenting Properties
Viewing Inherited Documentation
Use the--all flag to see documentation from parent classes:
MyChildClass followed by documentation from:
- Parent classes
- Implemented interfaces
- Used traits
- Example
ArrayIterator, then Iterator, Traversable, etc.Inheriting Documentation
If a docblock contains{@inheritdoc}, the --all flag is automatically enabled:
PHP Manual Integration
Installing the Manual
PsySH can download and use the official PHP manual for documenting core functions:The manual is downloaded from psysh.org and cached locally for offline use.
Language Support
Download the manual in different languages:- After Update
Manual Location
The PHP manual is stored in:- Linux/macOS:
~/.local/share/psysh/ - Windows:
%APPDATA%/PsySH/
Documenting Language Constructs
Thedoc command also works with PHP language constructs:
When Documentation is Missing
If no docblock exists and the PHP manual is not installed:Magic Variables
After runningdoc, several magic variables are set:
$__class- The documented class name$__method- The documented method name$__function- The documented function name$__namespace- The namespace of the documented element