Menu
Error Identifier: classConstant.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);
class Foo
{
public const BAR = 1;
}
echo Foo::BAZ;
Why is it reported? #
The code accesses a class constant that does not exist on the specified class. This will cause a fatal error at runtime. This is often caused by a typo in the constant name or by accessing a constant that was removed or renamed.
How to fix it #
Use the correct constant name:
<?php declare(strict_types = 1);
-echo Foo::BAZ;
+echo Foo::BAR;
Or define the missing constant:
<?php declare(strict_types = 1);
class Foo
{
public const BAR = 1;
+ public const BAZ = 2;
}
echo Foo::BAZ;
How to ignore this error #
You can use the identifier classConstant.notFound to ignore this error using a comment:
// @phpstan-ignore classConstant.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: classConstant.notFound
Rules that report this error #
- PHPStan\Rules\Classes\ClassConstantRule [1]