UnionType implements Type
Read onlyYes
FinalYes
Tags
Interfaces
Methods
- __construct() : mixed
- assert() : TLeft|TRight
- Checks if the value is of the type of given type.
- cast() : T
- Takes a value and when necessary casts it to the type of this object.
- fromArray() : type<string|int, TLeft|TRight>
- isOptionalType() : bool
- isValid() : bool
- Checks if the value is of the type of this object.
- normalize() : array{type: "union", left: array, right: array}
- toString() : string
- Returns a string representation of the type.
- types() : Types
Methods
__construct()
public
__construct(Type<string|int, TLeft> $left, Type<string|int, TRight> $right) : mixed
Parameters
assert()
Checks if the value is of the type of given type.
public
assert(mixed $value) : TLeft|TRight
Parameters
- $value : mixed
Return values
TLeft|TRightcast()
Takes a value and when necessary casts it to the type of this object.
public
cast(mixed $value) : T
When value is already of the type of this object, it is returned as is. When cast method is used, it will additionally narrow the type of the returned value for static analysis tools.
Parameters
- $value : mixed
Return values
TfromArray()
public
static fromArray(array{type: "union", left: array, right: array} $data) : type<string|int, TLeft|TRight>
Parameters
- $data : array{type: "union", left: array, right: array}
Return values
type<string|int, TLeft|TRight>isOptionalType()
public
isOptionalType() : bool
Return values
boolisValid()
Checks if the value is of the type of this object.
public
isValid(mixed $value) : bool
When isValid method is used, it will not narrow the type of the value for static analysis tools.
Parameters
- $value : mixed
Return values
boolnormalize()
public
normalize() : array{type: "union", left: array, right: array}
Return values
array{type: "union", left: array, right: array}toString()
Returns a string representation of the type.
public
toString() : string
- string - for type_string()
- int - for type_int()
- ?float - for type_optional(type_float())
Return values
stringtypes()
public
types() : Types