Error Identifier: doctrine.columnType

← Back to doctrine.*

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 Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class User
{
	#[ORM\Column(type: 'string')]
	private int $name;
}

Why is it reported? #

This error is reported by phpstan/phpstan-doctrine.

The PHP property type does not match the Doctrine column type mapping. In this example, the Doctrine column type string maps to string in PHP, but the property is declared as int. This mismatch means that:

  • The database can contain a value (string) that the property type (int) does not expect, or
  • The property can contain a value (int) that the database column (string) does not expect.

This mismatch can lead to type errors at runtime when Doctrine hydrates entities from the database or persists them.

The check also takes value ranges into account. For example, a smallint column can contain values in the range int<-32768, 32767>, or int<0, 65535> when the column is declared with options: ['unsigned' => true]. A property typed with a range that does not cover the column’s range is reported:

<?php declare(strict_types = 1);

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class Product
{
	/** @var int<0, 65535> */
	#[ORM\Column(type: 'smallint')]
	private int $quantity;
}

Here the database can contain int<-32768, 32767> but the property expects int<0, 65535>.

How to fix it #

Align the PHP property type with the Doctrine column type:

 <?php declare(strict_types = 1);
 
 use Doctrine\ORM\Mapping as ORM;

 #[ORM\Entity]
 class User
 {
 	#[ORM\Column(type: 'string')]
-	private int $name;
+	private string $name;
 }

Or change the Doctrine column type to match the property type:

 <?php declare(strict_types = 1);
 
 use Doctrine\ORM\Mapping as ORM;

 #[ORM\Entity]
 class User
 {
-	#[ORM\Column(type: 'string')]
+	#[ORM\Column(type: 'integer')]
 	private int $name;
 }

For smallint columns, make the property’s integer range match the column’s signedness:

 <?php declare(strict_types = 1);
 
 use Doctrine\ORM\Mapping as ORM;

 #[ORM\Entity]
 class Product
 {
 	/** @var int<0, 65535> */
-	#[ORM\Column(type: 'smallint')]
+	#[ORM\Column(type: 'smallint', options: ['unsigned' => true])]
 	private int $quantity;
 }

For nullable columns, make sure the property type includes null:

<?php declare(strict_types = 1);

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class User
{
	#[ORM\Column(type: 'string', nullable: true)]
	private ?string $name = null;
}

How to ignore this error #

You can use the identifier doctrine.columnType to ignore this error using a comment:

// @phpstan-ignore doctrine.columnType
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: doctrine.columnType

Rules that report this error #

  • PHPStan\Rules\Doctrine\ORM\EntityColumnRule [1] [2] phpstan/phpstan-doctrine
Theme
© 2026 PHPStan s.r.o.