Error Identifier: require.fileNotFound
Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.
Code example #
<?php declare(strict_types = 1);
require 'a-file-that-does-not-exist.php';
Why is it reported? #
The path passed to require() resolves to a file that does not exist on disk. At runtime, require will produce a fatal error when the file cannot be found. PHPStan checks the path against the current working directory, the PHP include path, and the directory of the analysed file.
How to fix it #
Correct the file path:
-require 'a-file-that-does-not-exist.php';
+require __DIR__ . '/existing-file.php';
Or ensure the file exists at the expected location. When paths are computed dynamically, PHPStan can only check constant string paths.
How to ignore this error #
You can use the identifier require.fileNotFound to ignore this error using a comment:
// @phpstan-ignore require.fileNotFound
codeThatProducesTheError();
You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:
parameters:
ignoreErrors:
-
identifier: require.fileNotFound
Rules that report this error #
- PHPStan\Rules\Keywords\RequireFileExistsRule [1]