| Methods |
public
|
__construct(Type $keyType, Type $itemType)
|
#
|
public
|
getKeyType(): Type
|
#
|
public
|
getItemType(): 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
|
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 $type): IsSuperTypeOfResult
"Does every value of $type belong to $this type?"
"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
|
isSuperTypeOfMixed(Type $type): IsSuperTypeOfResult
|
#
|
public
|
isSubTypeOf(Type $otherType): IsSuperTypeOfResult
Answers "is this compound type a subtype of $otherType?" from the compound type's perspective.
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.
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).
Implements
|
#
|
public
|
equals(Type $type): bool
|
#
|
public
|
describe(VerbosityLevel $level): string
|
#
|
public
|
hasOffsetValueType(Type $offsetType): TrinaryLogic
|
#
|
public
|
toNumber(): Type
Models numeric coercion for arithmetic operators.
Models numeric coercion for arithmetic operators.
Implements
|
#
|
public
|
toBitwiseNotType(): Type
Models the bitwise-not (~$x) operator. Returns ErrorType for types where ~ is undefined.
Models the bitwise-not (~$x) operator. Returns ErrorType for types where ~ is undefined.
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
|
toArrayOrTraversable(): 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.
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
|
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
The type of the first key; the union of the keys when their order is not known.
The type of the first key; the union of the keys when their order is not known.
Implements
|
#
|
public
|
getLastIterableKeyType(): Type
The type of the last key; the union of the keys when their order is not known.
The type of the last key; the union of the keys when their order is not known.
Implements
|
#
|
public
|
getIterableValueType(): Type
|
#
|
public
|
getFirstIterableValueType(): Type
The type of the first value; the union of the values when the order of the keys is not known.
The type of the first value; the union of the values when the order of the keys is not known.
Implements
|
#
|
public
|
getLastIterableValueType(): Type
The type of the last value; the union of the values when the order of the keys is not known.
The type of the last value; the union of the values when the order of the keys is not known.
Implements
|
#
|
public
|
getKindMask(): int
The kinds of values this type may hold, as TypeKind bits: a bit can be
set for a kind the type holds no value of, never the other way round.
Unions OR the masks of their members, intersections AND them.
The kinds of values this type may hold, as TypeKind bits: a bit can be
set for a kind the type holds no value of, never the other way round.
Unions OR the masks of their members, intersections AND them.
Implements
|
#
|
public
|
isNull(): TrinaryLogic
|
#
|
public
|
isConstantValue(): TrinaryLogic
Is Type of a known constant value? Includes literal strings, integers, floats, true, false, null, and array shapes.
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.
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
|
isString(): TrinaryLogic
|
#
|
public
|
isNumericString(): TrinaryLogic
|
#
|
public
|
isDecimalIntegerString(): TrinaryLogic
When isDecimalIntegerString() returns yes(), the type
is guaranteed to be cast to an integer in an array key.
Examples of constant values covered by this type: "0", "1", "1234", "-1"
When isDecimalIntegerString() returns yes(), the type
is guaranteed to be cast to an integer in an array key.
Examples of constant values covered by this type: "0", "1", "1234", "-1"
When isDecimalIntegerString() returns no(), the type represents strings containing non-decimal integers and other text.
These are guaranteed to stay as string in an array key.
Examples of constant values covered by this type: "+1", "00", "18E+3", "1.2", "1,3", "foo"
Implements
|
#
|
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
|
getStringRefinement(): ?int
The strings this type holds as StringRefinement cells, when they are
exactly the strings of those cells: string and the conjunctions of its
accessory types. Null for any other type, a constant string included.
The strings this type holds as StringRefinement cells, when they are
exactly the strings of those cells: string and the conjunctions of its
accessory types. Null for any other type, a constant string included.
Implements
|
#
|
public
|
isLowercaseString(): TrinaryLogic
|
#
|
public
|
isClassString(): TrinaryLogic
|
#
|
public
|
isUppercaseString(): 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
|
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
|
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<int>, 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<int>, infers T = int.
Implements
|
#
|
public
|
getReferencedTemplateTypes(TemplateTypeVariance $positionVariance): array
Returns the template types referenced by this Type, recursively.
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.
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.
Implements
|
#
|
public
|
traverseSimultaneously(Type $right, callable $cb): Type
Like traverse(), but walks two types simultaneously.
Like traverse(), but walks two types simultaneously.
Not used directly — use SimultaneousTypeTraverser::map() instead.
Implements
|
#
|
public
|
tryRemove(Type $typeToRemove): ?Type
|
#
|
public
|
arithmeticPower(Type $exponent, PhpVersion $phpVersion): Type
|
#
|
public
|
getFiniteTypes(): array
Returns a list of finite values this type can take.
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
|
#
|
public
|
toPhpDocNode(): TypeNode
|
#
|
public
|
toNativePhpTypeNode(NativeTypePosition $position)
The native PHP type declaration for this type at the given position,
widened to what the position allows, e.g. non-empty-string to string.
Returns null when the type cannot be declared natively there.
The native PHP type declaration for this type at the given position,
widened to what the position allows, e.g. non-empty-string to string.
Returns null when the type cannot be declared natively there.
Implements
|
#
|
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
|
#
|
public
|
hasUnresolvedTemplateArgumentType(): bool
Whether an UnresolvedTemplateArgumentType occurs anywhere in the type:
a template argument that is still being inferred.
Whether an UnresolvedTemplateArgumentType occurs anywhere in the type:
a template argument that is still being inferred.
Implements
|
#
|
public
|
toValueSet(): ValueSet
The values this type holds, by the kinds of values PHP's operators tell apart.
A union of types is the union of their sets, an intersection their intersection.
The values this type holds, by the kinds of values PHP's operators tell apart.
A union of types is the union of their sets, an intersection their intersection.
Implements
|
#
|
public
|
tryUnion(Type $otherType): ?Type
The union with the other type as this type alone, when this type absorbs
it by more than being its supertype, such as mixed~int|1 being
mixed~(int<min, 0>|int<2, max>). Null when it does not; TypeCombinator::union()
asks the other type the same.
The union with the other type as this type alone, when this type absorbs
it by more than being its supertype, such as mixed~int|1 being
mixed~(int<min, 0>|int<2, max>). Null when it does not; TypeCombinator::union()
asks the other type the same.
Implements
|
#
|
public
|
tryIntersect(Type $otherType): ?Type
The intersection with the other type as one type, when this type knows it
better than as the subtype of the two, such as Foo & object~Bar being
Foo~Bar. Null when it does not; TypeCombinator::intersect() asks the
other type the same, and asks both before it drops supertypes. A type that
compares the two to find out may return the one the other holds instead.
The intersection with the other type as one type, when this type knows it
better than as the subtype of the two, such as Foo & object~Bar being
Foo~Bar. Null when it does not; TypeCombinator::intersect() asks the
other type the same, and asks both before it drops supertypes. A type that
compares the two to find out may return the one the other holds instead.
Implements
|
#
|