ListType implements Type
Read onlyYes
FinalYes
Tags
Interfaces
Methods
- __construct() : mixed
- assert() : T
- Checks that the value is of the type of this object, throwing when it is not.
- cast() : T
- Takes a value and when necessary casts it to the type of this object.
- element() : Type<string|int, T>>
- fromArray() : ListType<string|int, array<int, mixed>>
- isValid() : bool
- Checks if the value is of the type of this object, returning a boolean instead of throwing.
-
normalize()
: array{type: "list", element: array
} - toString() : string
- Returns a string representation of the type.
Methods
__construct()
public
__construct(Type<string|int, T>> $element) : mixed
Parameters
- $element : Type<string|int, T>>
assert()
Checks that the value is of the type of this object, throwing when it is not.
public
assert(mixed $value) : T
Parameters
- $value : mixed
Return values
Tcast()
Takes a value and when necessary casts it to the type of this object.
public
cast(mixed $value) : T
Parameters
- $value : mixed
Return values
Telement()
public
element() : Type<string|int, T>>
Return values
Type<string|int, T>>fromArray()
public
static fromArray(array<string, mixed> $data) : ListType<string|int, array<int, mixed>>
Parameters
- $data : array<string, mixed>
Return values
ListType<string|int, array<int, mixed>>isValid()
Checks if the value is of the type of this object, returning a boolean instead of throwing.
public
isValid(mixed $value) : bool
When this method returns true, static analysis tools narrow the value's type to T at the call site (via @assert-if-true). Use this when you want to branch on the result; use assert() when you want the call to fail loudly on a mismatch.
Parameters
- $value : mixed
Return values
boolnormalize()
public
normalize() : array{type: "list", element: array}
Return values
array{type: "list", element: arraytoString()
Returns a string representation of the type.
public
toString() : string
- string - for type_string()
- int - for type_int()
- ?float - for type_optional(type_float())