rex_type
in package
Class for var casting.
Tags
Table of Contents
Methods
- array() : array<string|int, mixed>
- bool() : bool
- cast() : mixed
- Casts the variable $var to $vartype.
- instanceOf() : T
- int() : int
- notNull() : T
- nullOrBool() : bool|null
- nullOrInt() : int|null
- nullOrString() : string|null
- string() : string
Methods
array()
public
static array(mixed $value) : array<string|int, mixed>
Parameters
- $value : mixed
Tags
Return values
array<string|int, mixed>bool()
public
static bool(mixed $value) : bool
Parameters
- $value : mixed
Tags
Return values
boolcast()
Casts the variable $var to $vartype.
public
static cast(mixed $var, string|callable(mixed): mixed|array<int, int|string|BackedEnum|null>|array<int, array{0: string, 1: string|callable|list, 2?: mixed}> $vartype) : mixed
Possible types:
- 'bool' (or 'boolean')
- 'int' (or 'integer')
- 'double'
- 'string'
- 'float'
- 'real'
- 'object'
- 'array'
- 'array[
]', e.g. 'array[int]' - '' (don't cast)
- a callable
- ['foo', 'bar', 'baz'] (cast to ony of the given values)
- [
[
, , ], [ , , ], ... ]
Parameters
- $var : mixed
-
Variable to cast
- $vartype : string|callable(mixed): mixed|array<int, int|string|BackedEnum|null>|array<int, array{0: string, 1: string|callable|list, 2?: mixed}>
-
Variable type
Tags
Return values
mixed —Casted value
instanceOf()
public
static instanceOf(mixed $value, T> $class) : T
Parameters
- $value : mixed
- $class : T>
Tags
Return values
Tint()
public
static int(mixed $value) : int
Parameters
- $value : mixed
Tags
Return values
intnotNull()
public
static notNull(T|null $value) : T
Parameters
- $value : T|null
Tags
Return values
TnullOrBool()
public
static nullOrBool(mixed $value) : bool|null
Parameters
- $value : mixed
Tags
Return values
bool|nullnullOrInt()
public
static nullOrInt(mixed $value) : int|null
Parameters
- $value : mixed
Tags
Return values
int|nullnullOrString()
public
static nullOrString(mixed $value) : string|null
Parameters
- $value : mixed
Tags
Return values
string|nullstring()
public
static string(mixed $value) : string
Parameters
- $value : mixed