Menu

← Back to doctrine.*

Error Identifier: doctrine.finalConstructor

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 MyEntity
{
	final public function __construct(private string $name)
	{
	}
}

Why is it reported? #

This error is reported by phpstan/phpstan-doctrine.

Doctrine ORM uses proxy objects for lazy loading. These proxies extend the entity class and override the constructor to prevent premature initialization. If the constructor is declared final, Doctrine cannot create a proxy class for this entity, which breaks lazy loading functionality.

This applies to all Doctrine ORM entities (but not embeddables, which are not proxied).

How to fix it #

Remove the final keyword from the constructor:

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

 /**
  * @ORM\Entity()
  */
 class MyEntity
 {
-	final public function __construct(private string $name)
+	public function __construct(private string $name)
 	{
 	}
 }

How to ignore this error #

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

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

Rules that report this error #

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

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.