Menu

← Back to phpstanApi.*

Error Identifier: phpstanApi.classConstant

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);

use PHPStan\Analyser\NodeScopeResolver;

class Foo
{
	public function doFoo(): void
	{
		echo NodeScopeResolver::FOO;
	}
}

Why is it reported? #

The code accesses a class constant (including ::class) on a PHPStan class that is not covered by the backward compatibility promise. The class might change in a minor PHPStan version, which could break your code.

PHPStan marks certain classes with @api to indicate their constants are safe to access. Classes without this tag are considered internal and may have their constants changed or removed in any minor release.

How to fix it #

Use only class constants from classes that are covered by the backward compatibility promise (marked with @api). Check the PHPStan source code to see if the class whose constants you want to access is part of the public API.

If you believe the class should be covered by the backward compatibility promise, open a discussion at github.com/phpstan/phpstan/discussions.

Learn more: Backward Compatibility Promise

How to ignore this error #

You can use the identifier phpstanApi.classConstant to ignore this error using a comment:

// @phpstan-ignore phpstanApi.classConstant
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: phpstanApi.classConstant

Rules that report this error #

  • PHPStan\Rules\Api\ApiClassConstFetchRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.