Autoloading has been deprecated in favor of Discovering Symbols in PHPStan 0.12.26. Make sure to upgrade to the latest version and take advantage of the latest features!
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. ↩︎