Skip to content

Guide · Open source

How to use PHPStan: install, run and read its results

Updated · written with AI from the project's own documentation and checked against our catalogue data

PHPStan is an open-source static analysis tool for PHP. It reads your code and reports likely bugs, such as calls that will fail, without executing the code. This guide explains what it is, what you need before starting, how to get the source, and how to decide whether it fits your project.

PHPStanphpstan/phpstan · ★ 14.1k · MIT

Quick start

  1. 1Check PHP is installed. PHP is the only prerequisite listed in the README. Make sure it is available on your machine before continuing.
  2. 2Clone the repository. Run the Git clone command from the README to download the PHPStan source to your machine.
  3. 3Read the Getting Started guide. Open the official user guide on phpstan.org to learn how to run the analyser on your project.
  4. 4Configure your analysis. Use the Config Reference to set up the options that match your codebase.
  5. 5Add type information. Use PHPDoc types to give the analyser more context so it can check more of your code.
  6. 6Try the playground. Paste code into the online playground at phpstan.org/try to see sample results before committing to a setup.

What PHPStan does and why it helps

PHPStan focuses on finding errors in your code without running it. It can catch whole classes of bugs before you write tests for the code. The project describes its goal as moving PHP closer to compiled languages, where the correctness of each line can be checked before the line runs.

PHPStan complements tests rather than replacing them. It does not run your code, so runtime behaviour still needs a test suite.

What you need before you start

The only prerequisite listed in the project's README is PHP. PHPStan analyses PHP code only, so it is not useful for people who work mainly in other languages.

  • PHP installed on your machine
  • A PHP codebase you want to check

Get PHPStan from the repository

The README's install instruction is to clone the repository with Git. The clone command is shown below. The README does not describe further setup steps, so check the documentation on phpstan.org for how to run the analyser on your project.

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

Learn the workflow in the official documentation

All documentation lives on the phpstan.org website. The Getting Started and User Guide page is the best starting point for running analysis. The Config Reference covers configuration, and the PHPDocs pages explain how to add type information that helps the analyser.

The Extension Library and the developing extensions pages cover custom rules. The API Reference is hosted separately at apiref.phpstan.org.

  • Getting Started & User Guide: phpstan.org/user-guide/getting-started
  • Config Reference: phpstan.org/config-reference
  • PHPDocs Basics and PHPDoc Types: phpstan.org/writing-php-code
  • Extension Library: phpstan.org/user-guide/extension-library

Try PHPStan before installing

The project provides an online playground at phpstan.org/try. You can paste code there to see what the analyser reports without setting anything up locally.

Understand PHPStan Pro and its cost

PHPStan Pro is a paid add-on on top of open-source PHPStan. It adds a web UI for browsing errors, where you can open the offending line in your editor, and continuous analysis in watch mode that scans changed files in the background.

According to the README, you run it with the --pro option on PHPStan 0.12.45 or later, and after a 30-day free trial it costs 7 EUR per month for individuals or 70 EUR per month for teams of up to 25 members. If you need a graphical interface without paying, the web UI is not part of the free tool.

What people use it for

  • Catching calls that will fail before the code runs
  • Adding stricter checks to an existing PHP codebase
  • Helping a large team keep correctness checks consistent across many files
  • Reviewing results in a web UI through the paid PHPStan Pro add-on

Frequently asked questions

Is PHPStan free?

PHPStan itself is open source and released under the MIT licence. The PHPStan Pro add-on, which includes the web UI and watch mode, is paid after a 30-day free trial.

What does PHPStan require?

The README lists PHP as the prerequisite. PHPStan only analyses PHP code, so it does not help with other languages.

How do I install PHPStan?

The README's install instruction is to clone the repository from GitHub with Git. For running it on a project, follow the Getting Started guide on phpstan.org.

Does PHPStan run my code?

No. PHPStan checks code without executing it, so it complements tests rather than replacing them.

What are alternatives to PHPStan?

Projects comparable to PHPStan include Psalm, PHP_CodeSniffer and Phan. Each takes a different approach, so compare them against your team's needs.

Do I need PHPStan Pro?

No. PHPStan Pro is an optional paid add-on. The open-source tool is usable without it, but the web UI and watch mode are only part of Pro.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

PHPStan suits PHP developers and teams maintaining large PHP codebases who want bugs caught before tests run. It is a poor fit for non-PHP projects, for teams that need a runtime testing framework, or for anyone who needs a free graphical interface, since that is part of the paid Pro add-on.

Install options & downloads