Error Identifier: class.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);
class Foo extends NonexistentClass
{
}
Why is it reported? #
The code references a class that PHPStan cannot find. This can happen when extending, implementing, instantiating, or type-hinting a class that does not exist. Common causes include:
- A typo in the class name
- A missing
useimport statement - The class file is not included in the autoloader
- A missing Composer dependency
At runtime, referencing a non-existent class will cause a fatal error.
How to fix it #
Make sure the class exists and is properly autoloaded:
<?php declare(strict_types = 1);
+use App\Models\BaseClass;
+
-class Foo extends NonexistentClass
+class Foo extends BaseClass
{
}
If the class comes from an external package, make sure the package is installed:
composer require vendor/package
If PHPStan cannot find a class that does exist at runtime, configure the autoloader or scanFiles/scanDirectories in your PHPStan configuration.
Learn more: Discovering Symbols
How to ignore this error #
You can use the identifier class.notFound to ignore this error using a comment:
// @phpstan-ignore class.notFound
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: class.notFound
Rules that report this error #
- PHPStan\Rules\Arrays\ArrayDestructuringRule [1]
- PHPStan\Rules\Arrays\ArrayUnpackingRule [1]
- PHPStan\Rules\Arrays\InvalidKeyInArrayDimFetchRule [1]
- PHPStan\Rules\Arrays\InvalidKeyInArrayItemRule [1]
- PHPStan\Rules\Arrays\IterableInForeachRule [1]
- PHPStan\Rules\Arrays\NonexistentOffsetInArrayDimFetchRule [1]
- PHPStan\Rules\Arrays\OffsetAccessAssignOpRule [1]
- PHPStan\Rules\Arrays\OffsetAccessAssignmentRule [1]
- PHPStan\Rules\Arrays\OffsetAccessValueAssignmentRule [1]
- PHPStan\Rules\Arrays\UnpackIterableInArrayRule [1]
- PHPStan\Rules\Cast\EchoRule [1]
- PHPStan\Rules\Cast\InvalidCastRule [1]
- PHPStan\Rules\Cast\InvalidPartOfEncapsedStringRule [1]
- PHPStan\Rules\Cast\PrintRule [1]
- PHPStan\Rules\Classes\ClassAttributesRule [1]
- PHPStan\Rules\Classes\ClassConstantAttributesRule [1]
- PHPStan\Rules\Classes\ClassConstantRule [1] [2] [3]
- PHPStan\Rules\Classes\ExistingClassInClassExtendsRule [1]
- PHPStan\Rules\Classes\ExistingClassInInstanceOfRule [1]
- PHPStan\Rules\Classes\ImpossibleInstanceOfRule [1]
- PHPStan\Rules\Classes\InstantiationRule [1] [2]
- PHPStan\Rules\Classes\LocalTypeAliasesRule [1] [2]
- PHPStan\Rules\Classes\LocalTypeTraitAliasesRule [1] [2]
- PHPStan\Rules\Classes\LocalTypeTraitUseAliasesRule [1] [2]
- PHPStan\Rules\Classes\MethodTagRule [1]
- PHPStan\Rules\Classes\MethodTagTraitRule [1]
- PHPStan\Rules\Classes\MethodTagTraitUseRule [1]
- PHPStan\Rules\Classes\MixinRule [1]
- PHPStan\Rules\Classes\MixinTraitRule [1]
- PHPStan\Rules\Classes\MixinTraitUseRule [1]
- PHPStan\Rules\Classes\PropertyTagRule [1]
- PHPStan\Rules\Classes\PropertyTagTraitRule [1]
- PHPStan\Rules\Classes\PropertyTagTraitUseRule [1]
- PHPStan\Rules\Constants\ConstantAttributesRule [1]
- PHPStan\Rules\Constants\DynamicClassConstantFetchRule [1]
- PHPStan\Rules\EnumCases\EnumCaseAttributesRule [1]
- PHPStan\Rules\Exceptions\CaughtExceptionExistenceRule [1]
- PHPStan\Rules\Exceptions\ThrowExprTypeRule [1]
- PHPStan\Rules\Functions\ArrowFunctionAttributesRule [1]
- PHPStan\Rules\Functions\ArrowFunctionReturnTypeRule [1]
- PHPStan\Rules\Functions\CallCallablesRule [1]
- PHPStan\Rules\Functions\CallToFunctionParametersRule [1]
- PHPStan\Rules\Functions\CallUserFuncRule [1]
- PHPStan\Rules\Functions\ClosureAttributesRule [1]
- PHPStan\Rules\Functions\ClosureReturnTypeRule [1]
- PHPStan\Rules\Functions\ExistingClassesInArrowFunctionTypehintsRule [1] [2] [3] [4] [5]
- PHPStan\Rules\Functions\ExistingClassesInClosureTypehintsRule [1] [2] [3] [4] [5]
- PHPStan\Rules\Functions\ExistingClassesInTypehintsRule [1] [2] [3] [4] [5]
- PHPStan\Rules\Functions\FunctionAttributesRule [1]
- PHPStan\Rules\Functions\FunctionCallableRule [1]
- PHPStan\Rules\Functions\ImplodeParameterCastableToStringRule [1]
- PHPStan\Rules\Functions\ParamAttributesRule [1]
- PHPStan\Rules\Functions\ParameterCastableToNumberRule [1]
- PHPStan\Rules\Functions\ParameterCastableToStringRule [1]
- PHPStan\Rules\Functions\PrintfParameterTypeRule [1]
- PHPStan\Rules\Functions\ReturnTypeRule [1]
- PHPStan\Rules\Functions\SortParameterCastableToStringRule [1]
- PHPStan\Rules\Generators\YieldFromTypeRule [1]
- PHPStan\Rules\Generators\YieldTypeRule [1]
- PHPStan\Rules\Generics\ClassAncestorsRule [1]
- PHPStan\Rules\Generics\ClassTemplateTypeRule [1] [2]
- PHPStan\Rules\Generics\EnumAncestorsRule [1]
- PHPStan\Rules\Generics\FunctionTemplateTypeRule [1] [2]
- PHPStan\Rules\Generics\InterfaceAncestorsRule [1]
- PHPStan\Rules\Generics\InterfaceTemplateTypeRule [1] [2]
- PHPStan\Rules\Generics\MethodTagTemplateTypeRule [1] [2]
- PHPStan\Rules\Generics\MethodTagTemplateTypeTraitRule [1] [2]
- PHPStan\Rules\Generics\MethodTemplateTypeRule [1] [2]
- PHPStan\Rules\Generics\TraitTemplateTypeRule [1] [2]
- PHPStan\Rules\Generics\UsedTraitsRule [1]
- PHPStan\Rules\Methods\CallMethodsRule [1]
- PHPStan\Rules\Methods\CallStaticMethodsRule [1] [2]
- PHPStan\Rules\Methods\CallToMethodStatementWithNoDiscardRule [1]
- PHPStan\Rules\Methods\CallToMethodStatementWithoutSideEffectsRule [1]
- PHPStan\Rules\Methods\CallToStaticMethodStatementWithNoDiscardRule [1]
- PHPStan\Rules\Methods\CallToStaticMethodStatementWithoutSideEffectsRule [1]
- PHPStan\Rules\Methods\ExistingClassesInTypehintsRule [1] [2] [3] [4] [5]
- PHPStan\Rules\Methods\MethodAttributesRule [1]
- PHPStan\Rules\Methods\MethodCallableRule [1]
- PHPStan\Rules\Methods\ReturnTypeRule [1]
- PHPStan\Rules\Methods\StaticMethodCallableRule [1] [2]
- PHPStan\Rules\Operators\InvalidBinaryOperationRule [1]
- PHPStan\Rules\Operators\InvalidComparisonOperationRule [1]
- PHPStan\Rules\Operators\InvalidIncDecOperationRule [1]
- PHPStan\Rules\Operators\InvalidUnaryOperationRule [1]
- PHPStan\Rules\Operators\PipeOperatorRule [1]
- PHPStan\Rules\PhpDoc\FunctionAssertRule [1]
- PHPStan\Rules\PhpDoc\IncompatiblePhpDocTypeRule [1] [2]
- PHPStan\Rules\PhpDoc\IncompatiblePropertyHookPhpDocTypeRule [1] [2]
- PHPStan\Rules\PhpDoc\IncompatiblePropertyPhpDocTypeRule [1] [2]
- PHPStan\Rules\PhpDoc\InvalidPhpDocVarTagTypeRule [1]
- PHPStan\Rules\PhpDoc\MethodAssertRule [1]
- PHPStan\Rules\PhpDoc\RequireExtendsDefinitionClassRule [1]
- PHPStan\Rules\PhpDoc\RequireExtendsDefinitionTraitRule [1]
- PHPStan\Rules\PhpDoc\RequireImplementsDefinitionTraitRule [1]
- PHPStan\Rules\PhpDoc\SealedDefinitionClassRule [1]
- PHPStan\Rules\Properties\AccessPropertiesInAssignRule [1]
- PHPStan\Rules\Properties\AccessPropertiesRule [1]
- PHPStan\Rules\Properties\AccessStaticPropertiesInAssignRule [1] [2]
- PHPStan\Rules\Properties\AccessStaticPropertiesRule [1] [2]
- PHPStan\Rules\Properties\DefaultValueTypesAssignedToPropertiesRule [1]
- PHPStan\Rules\Properties\ExistingClassesInPropertiesRule [1]
- PHPStan\Rules\Properties\ExistingClassesInPropertyHookTypehintsRule [1] [2] [3] [4] [5]
- PHPStan\Rules\Properties\PropertyAttributesRule [1]
- PHPStan\Rules\Properties\PropertyHookAttributesRule [1]
- PHPStan\Rules\Properties\ReadingWriteOnlyPropertiesRule [1]
- PHPStan\Rules\Properties\TypesAssignedToPropertiesRule [1]
- PHPStan\Rules\Properties\WritingToReadOnlyPropertiesRule [1]
- PHPStan\Rules\RestrictedUsage\RestrictedClassConstantUsageRule [1]
- PHPStan\Rules\RestrictedUsage\RestrictedStaticMethodCallableUsageRule [1]
- PHPStan\Rules\RestrictedUsage\RestrictedStaticMethodUsageRule [1]
- PHPStan\Rules\RestrictedUsage\RestrictedStaticPropertyUsageRule [1]
- PHPStan\Rules\Traits\TraitAttributesRule [1]
- PHPStan\Rules\Variables\ParameterOutAssignedTypeRule [1]
- PHPStan\Rules\Variables\ParameterOutExecutionEndTypeRule [1]
- PHPStan\Rules\Variables\VariableCloningRule [1]