Menu

← Back to includeOnce.*

Error Identifier: includeOnce.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);

include_once 'a-file-that-does-not-exist.php';

Why is it reported? #

The path passed to include_once() does not point to an existing file. Unlike require_once, include_once will emit a warning rather than a fatal error at runtime when the file cannot be found, but the included code will not be available and may cause subsequent errors.

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);
 
-include_once 'a-file-that-does-not-exist.php';
+include_once __DIR__ . '/helpers.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 includeOnce.fileNotFound to ignore this error using a comment:

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

Rules that report this error #

  • PHPStan\Rules\Keywords\RequireFileExistsRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.