Menu

Error Identifier: doctrine.finalEntity

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]
final class User
{
	#[ORM\Id]
	#[ORM\Column]
	private int $id;
}

Why is it reported? #

This error is reported by the phpstan-doctrine extension.

A Doctrine entity class is declared as final. Doctrine uses proxy objects for lazy loading of entity relationships. Proxies are generated as subclasses of the entity class, but a final class cannot be extended. This means Doctrine cannot create proxy objects for this entity, which can cause problems with lazy loading.

How to fix it #

Remove the final keyword from the entity class:

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

 #[ORM\Entity]
-final class User
+class User
 {
 	#[ORM\Id]
 	#[ORM\Column]
 	private int $id;
 }

Starting with Doctrine ORM 3.4, lazy ghost objects are used by default for lazy loading. Lazy ghost objects do not require extending the entity class, so entities can be final. On older Doctrine ORM 3.x versions, lazy ghost objects can be enabled explicitly through the Configuration object:

$configuration->setLazyGhostObjectEnabled(true);

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Doctrine\ORM\EntityNotFinalRule [1] phpstan/phpstan-doctrine

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.