Skip to content

PHPStan

A PHP static analysis tool that finds bugs in code without running it.

Stars
14.1k
Forks
970
Licence
MIT
Language
PHP
Last update
4 days ago
Type
Dev tool

What it is

PHPStan is a tool that checks PHP code for errors without executing it. It reads your code and reports likely bugs, such as calls that will fail, before you run the code or write tests for it. The README says it aims to make PHP's correctness checkable line by line before running, similar in spirit to compiled languages.

  • Scan a PHP project for bugs before running it
  • Find errors in code that has no test coverage yet
  • Use the online playground at phpstan.org to try analysis on a snippet
  • Extend analysis with extensions, per the documentation links

Great for

  • PHP developers who want to catch bugs earlier than tests alone allow
  • Teams maintaining large PHP codebases
  • Developers who want stricter checks on existing PHP code

Not ideal for

  • Non-PHP developers, since it only analyzes PHP code
  • People looking for a runtime testing framework; PHPStan does not run your code, so it complements tests rather than replacing them
  • Those who need a graphical interface without paying, since the web UI is part of the paid PHPStan Pro add-on
Step-by-step guide: how to use PHPStanInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    See the README

    You'll need: PHP

    Clone the repository

    git clone https://github.com/phpstan/phpstan
  2. 2

    Run it

    • Read the Getting Started guide at phpstan.org/user-guide/getting-started
    • Install PHPStan following the documentation
    • Run it against your PHP project as described in the guide
    • Review the reported errors and fix the ones that matter
  3. 3

    Get the most out of it

    • Use the Config Reference to tune analysis settings
    • Add extensions from the Extension Library for framework-specific checks
    • Try PHPStan Pro's --pro option for a web UI and watch mode, if you want them and accept the paid trial terms
    • Read the PHPDoc guides to give the analyzer better type information

Downloads

Strengths

  • Finds whole classes of bugs without needing to run the code
  • Open source under the MIT license with an active project history
  • Official documentation, config reference, and an online playground are available

Trade-offs

  • The README does not detail setup steps, so you must follow the linked documentation to get started
  • Its most convenient interface (web UI and watch mode) is a paid add-on, PHPStan Pro
  • Static analysis can only judge what it can infer from the code, so results depend on the code's type information

How it compares

ProjectStarsTypeLevelUpdatedBest for
phpstan (this)14.1kDev toolintermediate4 days agoPHP developers who want to catch bugs earlier than tests alone allow
infer15.7kDev toolintermediate4 days agoDevelopers working on Java, C, C++, or Objective-C codebases
PHP-CS-Fixer13.6kDev toolbeginner5 days agoPHP teams that want consistent code style without manual review comments
ruff50.4kCLIbeginner4 days agoPython developers who want one tool for linting and formatting
grav15.7kAppintermediate4 days agoDevelopers who want a PHP website without running a database
static-analysis14.9kCurated listbeginner4 days agoDevelopers looking for a linter or analyzer for a specific language

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.