Menu

← Back to classConstant.*

Error Identifier: classConstant.class

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 FOO = 'foo';
	public const CLASS = 'bar';
}

Why is it reported? #

The name class is reserved for the special ::class constant syntax in PHP, which returns the fully qualified class name as a string (e.g. Foo::class evaluates to 'Foo'). Defining a class constant named class (case-insensitive) would conflict with this built-in language feature and is not allowed.

How to fix it #

Rename the class constant to something other than class:

 <?php declare(strict_types = 1);
 
 class Foo
 {
 	public const FOO = 'foo';
-	public const CLASS = 'bar';
+	public const CLASS_NAME = 'bar';
 }

Non-ignorable error #

This error cannot be ignored using @phpstan-ignore or the ignoreErrors configuration. Non-ignorable errors indicate code that would cause a crash or a fatal error at runtime, or a fundamental problem in the analysed code that must be addressed.

Rules that report this error #

  • PHPStan\Rules\Constants\ClassAsClassConstantRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.