Flow PHP

UnionType implements Type

Read onlyYes
FinalYes
Tags
template
implements

Interfaces

Type

Methods

__construct()  : mixed
assert()  : TLeft|TRight
Checks that the value is of the type of this object, throwing when it is not.
cast()  : TLeft|TRight
Takes a value and when necessary casts it to the type of this object.
fromArray()  : UnionType<mixed, mixed>
isOptionalType()  : bool
isValid()  : bool
Checks if the value is of the type of this object, returning a boolean instead of throwing.
memberFor()  : null|Type<string|int, mixed>
normalize()  : array{type: "union", left: array, right: array}
toString()  : string
Returns a string representation of the type.
types()  : Types<string|int, TLeft|TRight>

Methods

__construct()

public __construct(Type<string|int, TLeft$left, Type<string|int, TRight$right) : mixed
Parameters
$left : Type<string|int, TLeft>
$right : Type<string|int, TRight>

assert()

Checks that the value is of the type of this object, throwing when it is not.

public assert(mixed $value) : TLeft|TRight
Parameters
$value : mixed
Return values
TLeft|TRight

cast()

Takes a value and when necessary casts it to the type of this object.

public cast(mixed $value) : TLeft|TRight
Parameters
$value : mixed
Return values
TLeft|TRight

fromArray()

public static fromArray(array<string, mixed> $data) : UnionType<mixed, mixed>
Parameters
$data : array<string, mixed>
Return values
UnionType<mixed, mixed>

isOptionalType()

public isOptionalType() : bool
Return values
bool

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
bool

memberFor()

public memberFor(mixed $value) : null|Type<string|int, mixed>
Parameters
$value : mixed
Return values
null|Type<string|int, mixed>

the first non-null member this value is valid for

normalize()

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
string

types()

public types() : Types<string|int, TLeft|TRight>
Return values
Types<string|int, TLeft|TRight>
On this page

Search results