Class PHPStan\Type\IsSuperTypeOfResult

final

Result of a Type::isSuperTypeOf() check — whether one type is a supertype of another. Wraps a TrinaryLogic result together with human-readable reasons explaining the relationship. This is the primary mechanism for comparing types in PHPStan's type system. isSuperTypeOf() answers: "Can all values of type B also be values of type A?" For example:

  • (new StringType())->isSuperTypeOf(new ConstantStringType('hello')) → Yes
  • (new IntegerType())->isSuperTypeOf(new StringType()) → No
  • (new StringType())->isSuperTypeOf(new MixedType()) → Maybe This is distinct from accepts() which also considers rule levels and PHPDoc context. Use isSuperTypeOf() for type-theoretic comparisons and accepts() for assignability checks. Reasons can also be provided lazily (as Closure(): string) via $lazyReasons. This lets a type comparison attach an expensive-to-build explanation (e.g. one that calls describe() on large array shapes) without paying for it on the hot path — the closure only runs when getReasons() is called, i.e. when the reason is actually rendered. Can be converted to AcceptsResult via toAcceptsResult().
Methods