Menu

← Back to sealed.*

Error Identifier: sealed.onTrait

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);

/**
 * @phpstan-sealed AllowedClass
 */
trait MyTrait
{
    public function doSomething(): void
    {
    }
}

Why is it reported? #

The @phpstan-sealed PHPDoc tag is placed on a trait. This tag is only valid on classes and interfaces, where it restricts which types are allowed to extend or implement them. Traits cannot be extended or implemented directly – they are included via use statements – so the @phpstan-sealed tag has no meaning on a trait.

How to fix it #

Remove the @phpstan-sealed tag from the trait:

 <?php declare(strict_types = 1);
 
-/**
- * @phpstan-sealed AllowedClass
- */
 trait MyTrait
 {
     public function doSomething(): void
     {
     }
 }

If the goal is to restrict which classes can use this trait, consider converting the trait to an abstract class or an interface with a @phpstan-sealed tag:

 <?php declare(strict_types = 1);
 
 /**
  * @phpstan-sealed AllowedClass
  */
-trait MyTrait
+interface MyInterface
 {
-    public function doSomething(): void
-    {
-    }
+    public function doSomething(): void;
 }

How to ignore this error #

You can use the identifier sealed.onTrait to ignore this error using a comment:

// @phpstan-ignore sealed.onTrait
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: sealed.onTrait

Rules that report this error #

  • PHPStan\Rules\PhpDoc\SealedDefinitionTraitRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.