Menu

← Back to classConstant.*

Error Identifier: classConstant.internalClass

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

// In package vendor/some-library:

namespace SomeLibrary;

/** @internal */
class Config
{
	public const VERSION = '1.0';
}
<?php declare(strict_types = 1);

// In your code:

namespace App;

use SomeLibrary\Config;

$version = Config::VERSION;

Why is it reported? #

A constant is being accessed on a class that is marked as @internal. Internal classes are not meant to be used outside the package or namespace where they are defined. Accessing constants on internal classes creates a dependency on implementation details that may change without notice.

In the example above, Config::VERSION accesses a constant on the internal Config class from outside its namespace.

How to fix it #

Use a public (non-internal) API to access the information:

 <?php declare(strict_types = 1);
 
 namespace App;

-use SomeLibrary\Config;
+use SomeLibrary\Application;

-$version = Config::VERSION;
+$version = Application::getVersion();

If no public API exists, consider requesting one from the library maintainers. Relying on internal classes is fragile and may break on library updates.

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\InternalTag\RestrictedInternalClassConstantUsageExtension [1] [2]
  • PHPStan\Rules\InternalTag\RestrictedInternalClassNameUsageExtension [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.