Menu

← Back to classConstant.*

Error Identifier: classConstant.phpDocType

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
{
	/** @var string */
	const BAZ = 1;
}

Why is it reported? #

The @var PHPDoc tag on the class constant declares a type that is incompatible with the actual value assigned to the constant. In the example above, the PHPDoc declares the type as string, but the constant is assigned the integer value 1. This mismatch means the PHPDoc type does not accurately describe the constant’s value, which can lead to incorrect type inference in code that references the constant.

How to fix it #

Fix the PHPDoc type to match the actual value:

 <?php declare(strict_types = 1);
 
 class Foo
 {
-	/** @var string */
+	/** @var int */
 	const BAZ = 1;
 }

Or fix the value to match the declared type:

 <?php declare(strict_types = 1);
 
 class Foo
 {
 	/** @var string */
-	const BAZ = 1;
+	const BAZ = 'baz';
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Constants\ValueAssignedToClassConstantRule [1] [2]
  • PHPStan\Rules\PhpDoc\IncompatibleClassConstantPhpDocTypeRule [1] [2]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.