phan /phan
Phan is a static analyzer for PHP. Phan prefers to avoid false-positives and attempts to prove incorrectness rather than correctness.
★ 5,622⑂ 366👁 94⑃ 2,661● 2,987▤ 198
+0
Daily
5,622
stars
366
forks
94
watchers
2,661
prs
2,987
issues
198
releases
README
Phan is a static analyzer for PHP that prefers to minimize false-positives. Phan attempts to prove incorrectness rather than correctness. Phan looks for common issues and will verify type compatibility on various operations when type information is available or can be deduced. Phan has a good (but not comprehensive) understanding of flow control and can track values in a few use cases (e.g. arrays, integers, and strings). Getting Started The easiest way to use Phan is via Composer. composer require phan/phan With Phan installed, you can start analyzing your code immediately! Phan includes built-in stubs for enhanced type checking of PHP extensions. For new projects, use phan --init to create a .phan/config.php file with recommended settings and bundled stubs. You can also manually create a config file if you prefer. Once configured, you can run it via ./vendor/bin/phan. Phan 6 requires PHP 8.1+ with the php-ast extension (1.1.3+ is required for PHP 8.4+ support, and 1.1.4+ for PHP 8.6) and supports analyzing PHP version 8.1-8.6 syntax. Installation instructions for php-ast can be found here. (Phan can be used without php-ast by using the CLI option --allow-polyfill-parser, but there are slight differences in the parsing of doc comments) Alternative Installation Methods See Getting Started for alternative methods of using Phan and details on how to configure Phan for your project. Incrementally Strengthening Analysis Take a look at Incrementally Strengthening Analysis for some tips on how to slowly ramp up the strictness of the analysis as your code becomes better equipped to be analyzed. Installing Dependencies Take a look at Installing Phan Dependencies for help getting Phan's dependencies installed on your system. The Wiki has more information about using Phan. Tolerant parser dependency Phan relies on phan/phan-tolerant for the fallback parser and language-server mapping. The project is now consumed as a Composer dependency (microsoft/tolerant-php-parser, overridden to our fork via the repository entry in composer.json) rather than via a vendored subtree. To run the tolerant parser’s own PHPUnit suites, install its dev dependencies and invoke PHPUnit from the dependency directory: composer install cd vendor/microsoft/tolerant-php-parser composer install php -d zend.assertions=1 -d assert.exception=1 vendor/bin/phpunit --testsuite invariants,api When you need to refresh the parser to a newer commit, adjust the constraint in composer.json (or run composer update microsoft/tolerant-php-parser) and commit the resulting lockfile change. Features Phan is able to perform the following kinds of analysis: Check that all methods, functions, classes, traits, interfaces, constants, properties and variables are defined and accessible. Check for type safety and arity issues on method/function/closure calls. Check for PHP 8.6/8.5/8.4/8.3/8.2/8.1 backward compatibility. Check for features that weren't supported in o
Top issues
#3005dependencyListForFile()18 comments · 2019-07-25#3839Function templates don't work when check_docblock_signature_param_type_match is false15 comments · 2020-04-08#2311Create online playground?13 comments · 2019-01-09#3984Returning a variable that is assigned from a mixed return function, will not trigger any error.9 comments · 2020-06-26#4111Add way to *always* warn about missing real type signatures (parameters, return type, property)8 comments · 2020-08-04#1569Support for -k flag with daemon mode7 comments · 2018-03-15#3564PhanTypeInvalidDimOffset Invalid offset "..." of array type array{}6 comments · 2019-12-04#2082Suggestion: adopt semantic versioning6 comments · 2018-10-22
Latest release
6.0.11 6.0.11 2026-10-15Performance improvements: - In the 'balanced' process_file_assignment, also try splitting groups of files weighing more than half or a quarter of an even share (not only more than a whole share) and use the partition with the lowest predicted maximum load: a large class hierarchy that is under a share but placed first no longer leaves one analysis process noticeably heavier than the others (on a large codebase with --processes 4, the heaviest worker went from ~25 % above the mean to a few percent) (5601) - Speed up the loading of plugins' return type overrides and function call analyzers, whic