Menu

← Back to requireOnce.*

Error Identifier: requireOnce.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_once 'a-file-that-does-not-exist.php';

Why is it reported? #

The path passed to require_once() does not point to an existing file. PHP will produce a fatal error at runtime when it cannot find the file specified in a require_once statement.

PHPStan checks that the path resolves to an existing file by looking in the current working directory, the include path, and the directory of the script being analysed.

How to fix it #

Verify that the file path is correct and the file exists at the expected location:

 <?php declare(strict_types = 1);
 
-require_once 'a-file-that-does-not-exist.php';
+require_once __DIR__ . '/bootstrap.php';

If the file is resolved dynamically and PHPStan cannot determine the path statically, consider using a constant string expression that PHPStan can evaluate, such as __DIR__ combined with a relative path.

How to ignore this error #

You can use the identifier requireOnce.fileNotFound to ignore this error using a comment:

// @phpstan-ignore requireOnce.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: requireOnce.fileNotFound

Rules that report this error #

  • PHPStan\Rules\Keywords\RequireFileExistsRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.