Menu

← Back to trait.*

Error Identifier: trait.notFound

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

namespace App;

class Foo
{
	use NonexistentTrait;
}

Why is it reported? #

The use statement inside a class body references a trait that PHPStan cannot find. This can happen when:

  • The trait name contains a typo
  • A use import statement is missing
  • The trait file is not included in the autoloader
  • A Composer dependency is missing

At runtime, referencing a non-existent trait will cause a fatal error.

How to fix it #

Make sure the trait exists and is properly autoloaded:

 <?php declare(strict_types = 1);
 
 namespace App;

+use App\Traits\ExistingTrait;
+
 class Foo
 {
-	use NonexistentTrait;
+	use ExistingTrait;
 }

If the trait comes from an external package, make sure the package is installed:

composer require vendor/package

If PHPStan cannot find a trait that does exist at runtime, configure the autoloader or scanFiles/scanDirectories in your PHPStan configuration.

Learn more: Discovering Symbols

Non-ignorable error #

This error cannot be ignored using @phpstan-ignore or the ignoreErrors configuration. Non-ignorable errors indicate code that would cause a crash or a fatal error at runtime, or a fundamental problem in the analysed code that must be addressed.

Rules that report this error #

  • PHPStan\Rules\Classes\ExistingClassInTraitUseRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.