Represents a PHPStan type in the type system. This is the central interface of PHPStan's type system. Every type that PHPStan
can reason about implements this interface — from simple scalars like StringType
to complex generics like GenericObjectType. Each Type knows what it accepts, what is a supertype of it, what properties/methods/constants
it has, what operations it supports, and how to describe itself for error messages. Important: Never use instanceof to check types. For example, $type instanceof StringType
will miss union types, intersection types with accessory types, and other composite forms.
Always use the is*() methods or isSuperTypeOf() instead: // Wrong:
if ($type instanceof StringType) { ... } // Correct:
if ($type->isString()->yes()) { ... }
| Methods | ||
|---|---|---|
public
|
getReferencedClasses(): list<non-empty-string>
|
# |
public
|
getObjectClassNames(): list<non-empty-string>
|
# |
public
|
getObjectClassReflections(): list<ClassReflection>
|
# |
public
|
getClassStringObjectType(): Type
|
# |
public
|
getObjectTypeOrClassStringObjectType(): Type
|
# |
public
|
isObject(): TrinaryLogic
|
# |
public
|
isEnum(): TrinaryLogic
|
# |
public
|
getArrays(): list<ArrayType|ConstantArrayType>
|
# |
public
|
getConstantArrays(): list<ConstantArrayType>
|
# |
public
|
getConstantStrings(): list<ConstantStringType>
|
# |
public
|
accepts(Type $type, bool $strictTypes): AcceptsResult
|
# |
public
|
isSuperTypeOf(Type $type): IsSuperTypeOfResult
|
# |
public
|
equals(Type $type): bool
|
# |
public
|
describe(VerbosityLevel $level): string
|
# |
public
|
canAccessProperties(): TrinaryLogic
|
# |
public
|
hasProperty(string $propertyName): TrinaryLogic
|
# |
public
|
getProperty(string $propertyName, ClassMemberAccessAnswerer $scope): ExtendedPropertyReflection
|
# |
public
|
getUnresolvedPropertyPrototype(
string $propertyName,
ClassMemberAccessAnswerer $scope,
): UnresolvedPropertyPrototypeReflection
|
# |
public
|
hasInstanceProperty(string $propertyName): TrinaryLogic
|
# |
public
|
getInstanceProperty(string $propertyName, ClassMemberAccessAnswerer $scope): ExtendedPropertyReflection
|
# |
public
|
getUnresolvedInstancePropertyPrototype(
string $propertyName,
ClassMemberAccessAnswerer $scope,
): UnresolvedPropertyPrototypeReflection
|
# |
public
|
hasStaticProperty(string $propertyName): TrinaryLogic
|
# |
public
|
getStaticProperty(string $propertyName, ClassMemberAccessAnswerer $scope): ExtendedPropertyReflection
|
# |
public
|
getUnresolvedStaticPropertyPrototype(
string $propertyName,
ClassMemberAccessAnswerer $scope,
): UnresolvedPropertyPrototypeReflection
|
# |
public
|
canCallMethods(): TrinaryLogic
|
# |
public
|
hasMethod(string $methodName): TrinaryLogic
|
# |
public
|
getMethod(string $methodName, ClassMemberAccessAnswerer $scope): ExtendedMethodReflection
|
# |
public
|
getUnresolvedMethodPrototype(string $methodName, ClassMemberAccessAnswerer $scope): UnresolvedMethodPrototypeReflection
|
# |
public
|
canAccessConstants(): TrinaryLogic
|
# |
public
|
hasConstant(string $constantName): TrinaryLogic
|
# |
public
|
getConstant(string $constantName): ClassConstantReflection
|
# |
public
|
isIterable(): TrinaryLogic
|
# |
public
|
isIterableAtLeastOnce(): TrinaryLogic
|
# |
public
|
getArraySize(): Type
|
# |
public
|
getIterableKeyType(): Type
|
# |
public
|
getFirstIterableKeyType(): Type
|
# |
public
|
getLastIterableKeyType(): Type
|
# |
public
|
getIterableValueType(): Type
|
# |
public
|
getFirstIterableValueType(): Type
|
# |
public
|
getLastIterableValueType(): Type
|
# |
public
|
isArray(): TrinaryLogic
|
# |
public
|
isConstantArray(): TrinaryLogic
|
# |
public
|
isOversizedArray(): TrinaryLogic
|
# |
public
|
isList(): TrinaryLogic
|
# |
public
|
isOffsetAccessible(): TrinaryLogic
|
# |
public
|
isOffsetAccessLegal(): TrinaryLogic
|
# |
public
|
hasOffsetValueType(Type $offsetType): TrinaryLogic
|
# |
public
|
getOffsetValueType(Type $offsetType): Type
|
# |
public
|
setOffsetValueType(?Type $offsetType, Type $valueType, bool $unionValues = true): Type
|
# |
public
|
setExistingOffsetValueType(Type $offsetType, Type $valueType): Type
|
# |
public
|
unsetOffset(Type $offsetType): Type
|
# |
public
|
getKeysArrayFiltered(Type $filterValueType, TrinaryLogic $strict): Type
|
# |
public
|
getKeysArray(): Type
|
# |
public
|
getValuesArray(): Type
|
# |
public
|
chunkArray(Type $lengthType, TrinaryLogic $preserveKeys): Type
|
# |
public
|
fillKeysArray(Type $valueType): Type
|
# |
public
|
flipArray(): Type
|
# |
public
|
intersectKeyArray(Type $otherArraysType): Type
|
# |
public
|
popArray(): Type
|
# |
public
|
reverseArray(TrinaryLogic $preserveKeys): Type
|
# |
public
|
searchArray(Type $needleType, ?TrinaryLogic $strict = null): Type
|
# |
public
|
shiftArray(): Type
|
# |
public
|
shuffleArray(): Type
|
# |
public
|
sliceArray(Type $offsetType, Type $lengthType, TrinaryLogic $preserveKeys): Type
|
# |
public
|
spliceArray(Type $offsetType, Type $lengthType, Type $replacementType): Type
|
# |
public
|
getEnumCases(): list<EnumCaseObjectType>
|
# |
public
|
getEnumCaseObject(): ?EnumCaseObjectType
|
# |
public
|
getFiniteTypes(): list<Type>
|
# |
public
|
exponentiate(Type $exponent): Type
|
# |
public
|
isCallable(): TrinaryLogic
|
# |
public
|
getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope): list<CallableParametersAcceptor>
|
# |
public
|
isCloneable(): TrinaryLogic
|
# |
public
|
toBoolean(): BooleanType
|
# |
public
|
toNumber(): Type
|
# |
public
|
toInteger(): Type
|
# |
public
|
toFloat(): Type
|
# |
public
|
toString(): Type
|
# |
public
|
toArray(): Type
|
# |
public
|
toArrayKey(): Type
|
# |
public
|
toCoercedArgumentType(bool $strictTypes): self
|
# |
public
|
isSmallerThan(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
|
# |
public
|
isSmallerThanOrEqual(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
|
# |
public
|
isConstantValue(): TrinaryLogic
|
# |
public
|
isConstantScalarValue(): TrinaryLogic
|
# |
public
|
getConstantScalarTypes(): list<ConstantScalarType>
|
# |
public
|
getConstantScalarValues(): list<int|float|string|bool|null>
|
# |
public
|
isNull(): TrinaryLogic
|
# |
public
|
isTrue(): TrinaryLogic
|
# |
public
|
isFalse(): TrinaryLogic
|
# |
public
|
isBoolean(): TrinaryLogic
|
# |
public
|
isFloat(): TrinaryLogic
|
# |
public
|
isInteger(): TrinaryLogic
|
# |
public
|
isString(): TrinaryLogic
|
# |
public
|
isNumericString(): TrinaryLogic
|
# |
public
|
isNonEmptyString(): TrinaryLogic
|
# |
public
|
isNonFalsyString(): TrinaryLogic
|
# |
public
|
isLiteralString(): TrinaryLogic
|
# |
public
|
isLowercaseString(): TrinaryLogic
|
# |
public
|
isUppercaseString(): TrinaryLogic
|
# |
public
|
isClassString(): TrinaryLogic
|
# |
public
|
isVoid(): TrinaryLogic
|
# |
public
|
isScalar(): TrinaryLogic
|
# |
public
|
looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
|
# |
public
|
getSmallerType(PhpVersion $phpVersion): Type
|
# |
public
|
getSmallerOrEqualType(PhpVersion $phpVersion): Type
|
# |
public
|
getGreaterType(PhpVersion $phpVersion): Type
|
# |
public
|
getGreaterOrEqualType(PhpVersion $phpVersion): Type
|
# |
public
|
getTemplateType(class-string $ancestorClassName, string $templateTypeName): Type
|
# |
public
|
inferTemplateTypes(Type $receivedType): TemplateTypeMap
|
# |
public
|
getReferencedTemplateTypes(TemplateTypeVariance $positionVariance): list<TemplateTypeReference>
|
# |
public
|
toAbsoluteNumber(): Type
|
# |
public
|
traverse(callable(Type): Type $cb): Type
|
# |
public
|
traverseSimultaneously(Type $right, callable(Type $left, Type $right): Type $cb): Type
|
# |
public
|
toPhpDocNode(): TypeNode
|
# |
public
|
tryRemove(Type $typeToRemove): ?Type
|
# |
public
|
generalize(GeneralizePrecision $precision): Type
|
# |
public
|
hasTemplateOrLateResolvableType(): bool
|
# |