website/errors/trait.notFound.md
<?php declare(strict_types = 1);
namespace App;
class Foo
{
use NonexistentTrait;
}
The use statement inside a class body references a trait that PHPStan cannot find. This can happen when:
use import statement is missingAt runtime, referencing a non-existent trait will cause a fatal error.
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