Extended PHP type definition system.
Allows for more complete description of types in PHP, taking into account not only built-in types but also extended phpstan/psalm types, described in PHPDoc. This package itself only provides classes with type descriptions.
A common interface for all types. Provides several common methods:
public function isNullable(): bool;Checks that the specified type is nullable (that is, it allows null to be used as a value).
public function setNullable(): TypeInterface;Returns a new instance of the type that is nullable. If the type was already nullable, it returns itself.
public function __toString(): string;Returns a string representation of the type. This returns a full description of the type, suitable for PHPDoc.
public function toNativeTypeString(): string;Returns a string representation of a native PHP type.
public function isContravariantTo(TypeInterface $type): bool;Checks whether the given type is contravariant with respect to the passed $type.
An interface implemented by all non-generic or complex types. It provides no additional methods.
This namespace contains basic PHP types:
ArrayType- array typeBoolType- bool typeCallable- callable typeClassType- type for all non-anonymous classesFloatType- float typeIntType- int typeMixedType- mixed typeNeverType- never typeNotType- a special type for aliases that represents the negation of the typeNullType- null typeObjectType- object typeResourceType- resource typeStringType- string typeVoidType- void type
Special aliases for types:
ArrayKeyType- array-key (int|string)CallableStringType- callable-string (string)ClassStringType- class-string (string)FalseType- false (bool)FloatConstType- constant float (e.g. 1.23)IntConstType- constant int (e.g. 123)IntMaskOfType- int-mask-of (int)IntMaskType- int-mask (int)IntRangeType- int<min,max> (int)IterableType- iterable (array|\Traversable)ListType- list (array)NegativeIntType- negative-int (int)NonEmptyArrayType- non-empty-array (array)NonEmptyListType- non-empty-list (array)NonEmptyStringType- non-empty-string (string)NonFalsyStringType- non-falsy-string (string)NonNegativeIntType- non-negative-int (int)NonPositiveIntType- non-positive-int (int)NumericStringType- numeric-string (string)NumericType- numeric (int|float|numeric-string)PositiveIntType- positive-int (int)ScalarType- scalar (string|int|float|bool)StringConstType- constant string (e.g. "hello")TraitStringType- trait-string (string)TrueType- true (bool)TruthyStringType- truthy-string (string)
Complex types:
IntersectType- intersection type of several types (intersect)UnionType- union type of several types (union)