Class PHPStan\Type\Generic\TemplateTypeMap

final

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.
Methods