Error Identifier: constant.notFound
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);
echo UNDEFINED_CONSTANT;
Why is it reported? #
The code references a constant that PHPStan cannot find. This usually means the constant does not exist, is defined in a file that PHPStan does not scan, or is provided by an extension that is not loaded.
How to fix it #
If the constant is defined elsewhere, make sure PHPStan can discover it by including the file in scanFiles or scanDirectories:
parameters:
scanFiles:
- constants.php
If the constant name is a typo, correct it:
<?php declare(strict_types = 1);
-echo UNDEFNED_CONSTANT;
+echo UNDEFINED_CONSTANT;
How to ignore this error #
You can use the identifier constant.notFound to ignore this error using a comment:
// @phpstan-ignore constant.notFound
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: constant.notFound