| Methods |
public
|
__construct(list<Type> $types, bool $normalized = false)
|
#
|
public
|
getTypes(): list<Type>
|
#
|
public
|
filterTypes(callable(Type $type): bool $filterCb): Type
|
#
|
public
|
isNormalized(): bool
|
#
|
protected
|
getSortedTypes(): list<Type>
|
#
|
public
|
getReferencedClasses(): array
Returns all class names referenced anywhere in this type, recursively
(including generic arguments, callable signatures, etc.).
Returns all class names referenced anywhere in this type, recursively
(including generic arguments, callable signatures, etc.).
Implements
|
#
|
public
|
getObjectClassNames(): array
Returns class names of the object types this type directly represents.
Unlike getReferencedClasses(), excludes classes in generic arguments, etc.
Returns class names of the object types this type directly represents.
Unlike getReferencedClasses(), excludes classes in generic arguments, etc.
Implements
|
#
|
public
|
getObjectClassReflections(): array
|
#
|
public
|
getArrays(): array
|
#
|
public
|
getConstantArrays(): array
Only ConstantArrayType instances (array shapes with known keys).
Only ConstantArrayType instances (array shapes with known keys).
Implements
|
#
|
public
|
getConstantStrings(): array
|
#
|
public
|
accepts(Type $type, bool $strictTypes): AcceptsResult
Unlike isSuperTypeOf(), accepts() takes into account PHP's implicit type coercion.
With $strictTypes = false, int is accepted by float, and Stringable objects are
accepted by string.
Unlike isSuperTypeOf(), accepts() takes into account PHP's implicit type coercion.
With $strictTypes = false, int is accepted by float, and Stringable objects are
accepted by string.
Implements
|
#
|
public
|
isSuperTypeOf(Type $otherType): IsSuperTypeOfResult
"Does every value of $type belong to $this type?" Preferable to instanceof checks because it correctly handles
union types, intersection types, and all other composite types.
"Does every value of $type belong to $this type?" Preferable to instanceof checks because it correctly handles
union types, intersection types, and all other composite types.
Implements
|
#
|
public
|
isSubTypeOf(Type $otherType): IsSuperTypeOfResult
Answers "is this compound type a subtype of $otherType?" from the compound type's perspective. Called by simple types when they encounter a CompoundType argument in their isSuperTypeOf() method.
The compound type decomposes itself and calls $otherType->isSuperTypeOf() for each component. For example, UnionType(string|int)::isSubTypeOf(MixedType) asks MixedType whether it is
a supertype of string and int separately, then combines with extremeIdentity (all must pass).
Answers "is this compound type a subtype of $otherType?" from the compound type's perspective. Called by simple types when they encounter a CompoundType argument in their isSuperTypeOf() method.
The compound type decomposes itself and calls $otherType->isSuperTypeOf() for each component. For example, UnionType(string|int)::isSubTypeOf(MixedType) asks MixedType whether it is
a supertype of string and int separately, then combines with extremeIdentity (all must pass).
Implements
|
#
|
public
|
isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult
Answers "is this compound type accepted by $acceptingType?" from the compound type's perspective. Called by simple types when they encounter a CompoundType argument in their accepts() method.
The compound type decomposes itself and calls $acceptingType->accepts() for each component. For example, UnionType(string|int)::isAcceptedBy(StringType) asks StringType to accept
string and int separately, then combines results with extremeIdentity (all must pass).
Answers "is this compound type accepted by $acceptingType?" from the compound type's perspective. Called by simple types when they encounter a CompoundType argument in their accepts() method.
The compound type decomposes itself and calls $acceptingType->accepts() for each component. For example, UnionType(string|int)::isAcceptedBy(StringType) asks StringType to accept
string and int separately, then combines results with extremeIdentity (all must pass).
Overridden by
Implements
|
#
|
public
|
equals(Type $type): bool
|
#
|
public
|
describe(VerbosityLevel $level): string
|
#
|
public
|
getTemplateType(string $ancestorClassName, string $templateTypeName): Type
Returns actual template type for a given object. Example: @-template T
class Foo {} // $fooType is Foo
$t = $fooType->getTemplateType(Foo::class, 'T');
$t->isInteger(); // yes Returns ErrorType in case of a missing type.
Returns actual template type for a given object. Example: @-template T
class Foo {} // $fooType is Foo
$t = $fooType->getTemplateType(Foo::class, 'T');
$t->isInteger(); // yes Returns ErrorType in case of a missing type.
Implements
|
#
|
public
|
isObject(): TrinaryLogic
|
#
|
public
|
isEnum(): TrinaryLogic
|
#
|
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
Unlike getInstanceProperty(), this defers template type resolution.
Use getInstanceProperty() in most rule implementations.
Unlike getInstanceProperty(), this defers template type resolution.
Use getInstanceProperty() in most rule implementations.
Implements
|
#
|
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
Unlike getMethod(), this defers template type and static type resolution.
Use getMethod() in most rule implementations.
Unlike getMethod(), this defers template type and static type resolution.
Use getMethod() in most rule implementations.
Implements
|
#
|
public
|
canAccessConstants(): TrinaryLogic
|
#
|
public
|
hasConstant(string $constantName): TrinaryLogic
|
#
|
public
|
getConstant(string $constantName): ClassConstantReflection
|
#
|
public
|
isIterable(): TrinaryLogic
|
#
|
public
|
isIterableAtLeastOnce(): TrinaryLogic
|
#
|
public
|
getArraySize(): Type
Returns the count of elements as a Type (typically IntegerRangeType).
Returns the count of elements as a Type (typically IntegerRangeType).
Implements
|
#
|
public
|
getIterableKeyType(): Type
Works for both arrays and Traversable objects.
Works for both arrays and Traversable objects.
Implements
|
#
|
public
|
getFirstIterableKeyType(): Type
|
#
|
public
|
getLastIterableKeyType(): Type
|
#
|
public
|
getIterableValueType(): Type
|
#
|
public
|
getFirstIterableValueType(): Type
|
#
|
public
|
getLastIterableValueType(): Type
|
#
|
public
|
isArray(): TrinaryLogic
|
#
|
public
|
isConstantArray(): TrinaryLogic
|
#
|
public
|
isOversizedArray(): TrinaryLogic
An oversized array is a constant array shape that grew too large to track
precisely and was degraded to a generic array type.
An oversized array is a constant array shape that grew too large to track
precisely and was degraded to a generic array type.
Implements
|
#
|
public
|
isList(): TrinaryLogic
A list is an array with sequential integer keys starting from 0 with no gaps.
A list is an array with sequential integer keys starting from 0 with no gaps.
Implements
|
#
|
public
|
isString(): TrinaryLogic
|
#
|
public
|
isNumericString(): TrinaryLogic
|
#
|
public
|
isNonEmptyString(): TrinaryLogic
|
#
|
public
|
isNonFalsyString(): TrinaryLogic
Non-falsy string is a non-empty string that is also not '0'.
Stricter subset of non-empty-string.
Non-falsy string is a non-empty string that is also not '0'.
Stricter subset of non-empty-string.
Implements
|
#
|
public
|
isLiteralString(): TrinaryLogic
A literal-string is a string composed entirely from string literals
in the source code (not from user input). Used for SQL injection prevention.
A literal-string is a string composed entirely from string literals
in the source code (not from user input). Used for SQL injection prevention.
Implements
|
#
|
public
|
isLowercaseString(): TrinaryLogic
|
#
|
public
|
isUppercaseString(): TrinaryLogic
|
#
|
public
|
isClassString(): TrinaryLogic
|
#
|
public
|
getClassStringObjectType(): Type
Returns the object type for a class-string or literal class name string.
For non-class-string types, returns ErrorType.
Returns the object type for a class-string or literal class name string.
For non-class-string types, returns ErrorType.
Implements
|
#
|
public
|
getObjectTypeOrClassStringObjectType(): Type
Like getClassStringObjectType(), but also returns object types as-is.
Used for $classOrObject::method() where the left side can be either.
Like getClassStringObjectType(), but also returns object types as-is.
Used for $classOrObject::method() where the left side can be either.
Implements
|
#
|
public
|
isVoid(): TrinaryLogic
|
#
|
public
|
isScalar(): TrinaryLogic
|
#
|
public
|
looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
|
#
|
public
|
isOffsetAccessible(): TrinaryLogic
|
#
|
public
|
isOffsetAccessLegal(): TrinaryLogic
Whether accessing a non-existent offset is safe (won't cause errors).
Unlike isOffsetAccessible() which checks if offset access is supported at all.
Whether accessing a non-existent offset is safe (won't cause errors).
Unlike isOffsetAccessible() which checks if offset access is supported at all.
Implements
|
#
|
public
|
hasOffsetValueType(Type $offsetType): TrinaryLogic
|
#
|
public
|
getOffsetValueType(Type $offsetType): Type
|
#
|
public
|
setOffsetValueType(?Type $offsetType, Type $valueType, bool $unionValues = true): Type
May add a new key. When $offsetType is null, appends (like $a[] = $value).
May add a new key. When $offsetType is null, appends (like $a[] = $value).
Implements
|
#
|
public
|
setExistingOffsetValueType(Type $offsetType, Type $valueType): Type
Unlike setOffsetValueType(), assumes the key already exists.
Preserves the array shape and list type.
Unlike setOffsetValueType(), assumes the key already exists.
Preserves the array shape and list type.
Implements
|
#
|
public
|
unsetOffset(Type $offsetType): Type
|
#
|
public
|
getKeysArrayFiltered(Type $filterValueType, TrinaryLogic $strict): Type
Models array_keys($array, $searchValue, $strict).
Models array_keys($array, $searchValue, $strict).
Implements
|
#
|
public
|
getKeysArray(): Type
Models array_keys($array).
Models array_keys($array).
Implements
|
#
|
public
|
getValuesArray(): Type
Models array_values($array).
Models array_values($array).
Implements
|
#
|
public
|
chunkArray(Type $lengthType, TrinaryLogic $preserveKeys): Type
Models array_chunk($array, $length, $preserveKeys).
Models array_chunk($array, $length, $preserveKeys).
Implements
|
#
|
public
|
fillKeysArray(Type $valueType): Type
Models array_fill_keys($keys, $value).
Models array_fill_keys($keys, $value).
Implements
|
#
|
public
|
flipArray(): Type
Models array_flip($array).
Models array_flip($array).
Implements
|
#
|
public
|
intersectKeyArray(Type $otherArraysType): Type
Models array_intersect_key($array, ...$otherArrays).
Models array_intersect_key($array, ...$otherArrays).
Implements
|
#
|
public
|
popArray(): Type
Models array_pop() effect on the array.
Models array_pop() effect on the array.
Implements
|
#
|
public
|
reverseArray(TrinaryLogic $preserveKeys): Type
Models array_reverse($array, $preserveKeys).
Models array_reverse($array, $preserveKeys).
Implements
|
#
|
public
|
searchArray(Type $needleType, ?TrinaryLogic $strict = null): Type
Models array_search($needle, $array, $strict).
Models array_search($needle, $array, $strict).
Implements
|
#
|
public
|
shiftArray(): Type
Models array_shift() effect on the array.
Models array_shift() effect on the array.
Implements
|
#
|
public
|
shuffleArray(): Type
Models shuffle() effect on the array. Result is always a list.
Models shuffle() effect on the array. Result is always a list.
Implements
|
#
|
public
|
sliceArray(Type $offsetType, Type $lengthType, TrinaryLogic $preserveKeys): Type
Models array_slice($array, $offset, $length, $preserveKeys).
Models array_slice($array, $offset, $length, $preserveKeys).
Implements
|
#
|
public
|
spliceArray(Type $offsetType, Type $lengthType, Type $replacementType): Type
Models array_splice() effect on the array (the modified array, not the removed portion).
Models array_splice() effect on the array (the modified array, not the removed portion).
Implements
|
#
|
public
|
getEnumCases(): array
|
#
|
public
|
getEnumCaseObject(): ?EnumCaseObjectType
Returns the single enum case this type represents, or null if not exactly one case.
Returns the single enum case this type represents, or null if not exactly one case.
Implements
|
#
|
public
|
isCallable(): TrinaryLogic
|
#
|
public
|
getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope): array
|
#
|
public
|
isCloneable(): TrinaryLogic
|
#
|
public
|
isSmallerThan(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
|
#
|
public
|
isSmallerThanOrEqual(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
|
#
|
public
|
isNull(): TrinaryLogic
|
#
|
public
|
isConstantValue(): TrinaryLogic
Is Type of a known constant value? Includes literal strings, integers, floats, true, false, null, and array shapes. Unlike isConstantScalarValue(), this also returns yes for constant array types (array shapes
with known keys and values). Use this when you need to detect any constant value including arrays.
Is Type of a known constant value? Includes literal strings, integers, floats, true, false, null, and array shapes. Unlike isConstantScalarValue(), this also returns yes for constant array types (array shapes
with known keys and values). Use this when you need to detect any constant value including arrays.
Implements
|
#
|
public
|
isConstantScalarValue(): TrinaryLogic
Is Type of a known constant scalar value? Includes literal strings, integers, floats, true, false, and null. Unlike isConstantValue(), this does NOT return yes for array shapes.
Use this when you specifically need scalar constants only.
Is Type of a known constant scalar value? Includes literal strings, integers, floats, true, false, and null. Unlike isConstantValue(), this does NOT return yes for array shapes.
Use this when you specifically need scalar constants only.
Implements
|
#
|
public
|
getConstantScalarTypes(): array
|
#
|
public
|
getConstantScalarValues(): array
|
#
|
public
|
isTrue(): TrinaryLogic
|
#
|
public
|
isFalse(): TrinaryLogic
|
#
|
public
|
isBoolean(): TrinaryLogic
|
#
|
public
|
isFloat(): TrinaryLogic
|
#
|
public
|
isInteger(): TrinaryLogic
|
#
|
public
|
getSmallerType(PhpVersion $phpVersion): Type
Type narrowing methods for comparison operators.
For example, for ConstantIntegerType(5), getSmallerType() returns int<min, 4>.
Type narrowing methods for comparison operators.
For example, for ConstantIntegerType(5), getSmallerType() returns int<min, 4>.
Implements
|
#
|
public
|
getSmallerOrEqualType(PhpVersion $phpVersion): Type
|
#
|
public
|
getGreaterType(PhpVersion $phpVersion): Type
|
#
|
public
|
getGreaterOrEqualType(PhpVersion $phpVersion): Type
|
#
|
public
|
isGreaterThan(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
Compares this compound type against $otherType using greater-than semantics. Used for comparison operators (>). Each compound type decomposes the comparison
across its members (e.g., IntegerRangeType checks whether all values in the range
are greater than the other type).
Compares this compound type against $otherType using greater-than semantics. Used for comparison operators (>). Each compound type decomposes the comparison
across its members (e.g., IntegerRangeType checks whether all values in the range
are greater than the other type).
Implements
|
#
|
public
|
isGreaterThanOrEqual(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
Compares this compound type against $otherType using greater-than-or-equal semantics. Used for comparison operators (>=). Same decomposition strategy as isGreaterThan().
Compares this compound type against $otherType using greater-than-or-equal semantics. Used for comparison operators (>=). Same decomposition strategy as isGreaterThan().
Implements
|
#
|
public
|
toBoolean(): BooleanType
|
#
|
public
|
toNumber(): Type
Models numeric coercion for arithmetic operators.
Models numeric coercion for arithmetic operators.
Implements
|
#
|
public
|
toAbsoluteNumber(): Type
|
#
|
public
|
toString(): Type
Models the (string) cast.
Models the (string) cast.
Implements
|
#
|
public
|
toInteger(): Type
|
#
|
public
|
toFloat(): Type
|
#
|
public
|
toArray(): Type
|
#
|
public
|
toArrayKey(): Type
Models PHP's implicit array key coercion: floats truncated to int,
booleans become 0/1, null becomes '', numeric strings become int.
Models PHP's implicit array key coercion: floats truncated to int,
booleans become 0/1, null becomes '', numeric strings become int.
Implements
|
#
|
public
|
toCoercedArgumentType(bool $strictTypes): Type
Returns how this type might change when passed to a typed parameter
or assigned to a typed property. With $strictTypes = true: int widens to int|float (since int is accepted
by float parameters in strict mode).
With $strictTypes = false: additional coercions apply, e.g. Stringable
objects are accepted by string parameters. Used internally to determine what types a value might be coerced to
when checking parameter acceptance.
Returns how this type might change when passed to a typed parameter
or assigned to a typed property. With $strictTypes = true: int widens to int|float (since int is accepted
by float parameters in strict mode).
With $strictTypes = false: additional coercions apply, e.g. Stringable
objects are accepted by string parameters. Used internally to determine what types a value might be coerced to
when checking parameter acceptance.
Implements
|
#
|
public
|
inferTemplateTypes(Type $receivedType): TemplateTypeMap
Infers the real types of TemplateTypes found in $this, based on
the received Type. E.g. if $this is array<T> and $receivedType
is array, infers T = int.
Infers the real types of TemplateTypes found in $this, based on
the received Type. E.g. if $this is array<T> and $receivedType
is array, infers T = int.
Overridden by
Implements
|
#
|
public
|
inferTemplateTypesOn(Type $templateType): TemplateTypeMap
|
#
|
public
|
getReferencedTemplateTypes(TemplateTypeVariance $positionVariance): array
Returns the template types referenced by this Type, recursively. The return value is a list of TemplateTypeReferences, who contain the
referenced template type as well as the variance position in which it was
found. For example, calling this on array<Foo<T>,Bar> (with T a template type)
will return one TemplateTypeReference for the type T.
Returns the template types referenced by this Type, recursively. The return value is a list of TemplateTypeReferences, who contain the
referenced template type as well as the variance position in which it was
found. For example, calling this on array<Foo<T>,Bar> (with T a template type)
will return one TemplateTypeReference for the type T.
Parameters
| $positionVariance |
The variance position in
which the receiver type was
found.
|
Implements
|
#
|
public
|
traverse(callable $cb): Type
Returns a new instance with all inner types mapped through $cb.
Returns the same instance if inner types did not change. Not used directly — use TypeTraverser::map() instead.
Returns a new instance with all inner types mapped through $cb.
Returns the same instance if inner types did not change. Not used directly — use TypeTraverser::map() instead.
Overridden by
Implements
|
#
|
public
|
traverseSimultaneously(Type $right, callable $cb): Type
Like traverse(), but walks two types simultaneously. Not used directly — use SimultaneousTypeTraverser::map() instead.
Like traverse(), but walks two types simultaneously. Not used directly — use SimultaneousTypeTraverser::map() instead.
Overridden by
Implements
|
#
|
public
|
tryRemove(Type $typeToRemove): ?Type
|
#
|
public
|
exponentiate(Type $exponent): Type
|
#
|
public
|
getFiniteTypes(): array
Returns a list of finite values this type can take. Examples: - for bool: [true, false]
- for int<0, 3>: [0, 1, 2, 3]
- for enums: list of enum cases
- for scalars: the scalar itself For infinite types it returns an empty array.
Returns a list of finite values this type can take. Examples: - for bool: [true, false]
- for int<0, 3>: [0, 1, 2, 3]
- for enums: list of enum cases
- for scalars: the scalar itself For infinite types it returns an empty array.
Implements
|
#
|
protected
|
unionResults(callable(Type $type): TrinaryLogic $getResult): TrinaryLogic
|
#
|
protected
|
unionTypes(callable(Type $type): Type $getType): Type
|
#
|
protected
|
pickFromTypes<T>(callable(Type $type): list<T> $getValues, callable(Type $type): bool $criteria): list<T>
|
#
|
public
|
toPhpDocNode(): TypeNode
|
#
|
public
|
hasTemplateOrLateResolvableType(): bool
Performance optimization to skip template resolution when no templates are present.
Performance optimization to skip template resolution when no templates are present.
Implements
|
#
|