Namespace PHPStan\Type\Generic

Classes
GenericClassStringType
GenericObjectType
GenericStaticType
TemplateArrayType
TemplateBenevolentUnionType
TemplateBooleanType
TemplateConstantArrayType
TemplateConstantIntegerType
TemplateConstantStringType
TemplateFloatType
TemplateGenericObjectType
TemplateIntegerType
TemplateIntersectionType
TemplateIterableType
TemplateKeyOfType
TemplateMixedType
TemplateObjectShapeType
TemplateObjectType
TemplateObjectWithoutClassType
TemplateStrictMixedType
TemplateStringType
TemplateTypeMap

Maps template type parameter names to their resolved types. This is the core data structure for PHPStan's generics support. When a class declares @template T, @template U of object, etc., the TemplateTypeMap tracks what concrete types T and U resolve to in a particular context. Two kinds of type bindings are tracked:

  • types (upper bounds): The concrete type inferred or declared for each template. For @template T of Countable, if T is inferred as array, types maps T → array.
  • lowerBoundTypes: Types inferred from contravariant positions (e.g. parameter types). Used during type inference to narrow template types from below. TemplateTypeMap supports set operations (union, intersect, benevolentUnion) that combine maps from different code paths, and resolveToBounds() which replaces unresolved template types with their declared bounds. Common usage: ParametersAcceptor::getTemplateTypeMap() returns the template declarations, and ParametersAcceptor::getResolvedTemplateTypeMap() returns inferred concrete types. Type::inferTemplateTypes() produces a TemplateTypeMap from a concrete type.
TemplateTypeScope
TemplateTypeVariance

Represents the variance of a template type parameter. Variance describes how subtyping of a generic type relates to subtyping of its type arguments. For a class Box<T>: - Invariant (default): Box<Cat> is NOT a subtype of Box<Animal>, even though Cat extends Animal. The type argument must match exactly. Declared with @template T.

  • Covariant: Box<Cat> IS a subtype of Box<Animal>. Safe when T only appears in "output" positions (return types). Declared with @template-covariant T.
  • Contravariant: Box<Animal> IS a subtype of Box<Cat>. Safe when T only appears in "input" positions (parameter types). Declared with @template-contravariant T.
  • Bivariant: The type argument is ignored for subtyping purposes. Rarely used.
  • Static: Special variance for static return type in template context. Variance composition follows standard rules — e.g. covariant composed with contravariant yields contravariant. This is used when template types appear inside nested generic types.
TemplateTypeVarianceMap
TemplateUnionType
Interfaces
TemplateType