Interested in mastering your PHP craft and getting the most out of PHPStan? Ondřej Mirtes (the creator of PHPStan) will hold a 3-hour interactive workshop as part of the online Dutch PHP Conference on June 25th 2020.
You'll learn how to install, configure, and run PHPStan, receive tips on how to write code so that PHPStan can be as powerful as possible, and you will also be able to write your own PHPStan rules once the workshop is over.Buy a ticket and secure your place! »
PHPStan needs a working autoloader to access reflection of the analysed classes. It uses Composer autoloader in the project by looking at
vendor/autoload.php from the current working directory. Use the
autoload-dev sections in
composer.json to configure the autoloader.
If PHPStan complains about some non-existent classes  and you’re sure the classes exist in the codebase and you don’t want to use Composer autoloader, you can specify directories to scan and concrete files to include using
autoload_files parameters in the configuration file.
autoload_directories is for discovering classes, interfaces, and traits,
autoload_files is used for loading function definitions.
Relative paths in the
autoload_files keys are resolved based on the directory of the config file is in.
You can also use a custom autoloader.
PHPStan doesn’t automatically know about global constants in the analysed project. You need to provide them by defining all of them in a single place and let PHPStan autoload this file.
Create a file
constants.php with this content:
And put it into the
autoload_files key in the configuration file:
This manifests are “Class not found” message in the PHPStan’s output, even when analysing the file the class is in. ↩︎