Static analyzer for PHP that favors proving incorrectness over exhaustive proof and aims to limit false positives. Runs from the CLI or editor integrations.
Overview
Phan checks PHP codebases for type inconsistencies, undefined symbols, unsafe calls, dead code, and similar defects. It emphasizes demonstrating that code may be wrong rather than certifying correctness, and prefers fewer false alarms.
Analysis uses AST parsing (via php-ast when available), understands flow in limited cases, and reads PHPDoc including generics, array shapes, and union types. It can flag backward-compatibility issues across PHP 8.x features, unused variables, redundant conditions, and inheritance problems.
Projects configure a .phan/config.php file listing roots to analyze; Composer installation is the usual path. Output formats include text, JSON, Checkstyle, and others. Optional plugins extend checks, and Phan supports parallel runs when pcntl is available.
Editor and IDE workflows can use the Language Server Protocol or daemon mode for per-file checks. An in-browser demo can run Phan without a local install when sufficient memory is available.
Key features
- Type and arity checking on calls
- PHPDoc and generic type support
- Dead and unreachable code detection
- Unused variable and import detection
- Inheritance and override validation
- Configurable strictness for large codebases
- Multiple report output formats
- Language server and daemon modes
Use cases
- CI static analysis for PHP
- Gradually tightening legacy PHP quality
- IDE inline error checking
- Finding unused code paths
- PHP 8.x compatibility review