Documentation

rex_type
in package

Class for var casting.

Tags
author

gharlan

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
psalm-assert

array $value

psalm-pure
Return values
array<string|int, mixed>

bool()

public static bool(mixed $value) : bool
Parameters
$value : mixed
Tags
psalm-assert

bool $value

psalm-pure
Return values
bool

cast()

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
throws
InvalidArgumentException
psalm-taint-specialize
Return values
mixed

Casted value

instanceOf()

public static instanceOf(mixed $value, T> $class) : T
Parameters
$value : mixed
$class : T>
Tags
template

T of object

psalm-assert

T $value

psalm-pure
Return values
T

int()

public static int(mixed $value) : int
Parameters
$value : mixed
Tags
psalm-assert

int $value

psalm-pure
Return values
int

notNull()

public static notNull(T|null $value) : T
Parameters
$value : T|null
Tags
template

T

psalm-assert

!null $value

psalm-pure
Return values
T

nullOrBool()

public static nullOrBool(mixed $value) : bool|null
Parameters
$value : mixed
Tags
psalm-assert

?bool $value

psalm-pure
Return values
bool|null

nullOrInt()

public static nullOrInt(mixed $value) : int|null
Parameters
$value : mixed
Tags
psalm-assert

?int $value

psalm-pure
Return values
int|null

nullOrString()

public static nullOrString(mixed $value) : string|null
Parameters
$value : mixed
Tags
psalm-assert

?string $value

psalm-pure
Return values
string|null

string()

public static string(mixed $value) : string
Parameters
$value : mixed
Tags
psalm-assert

string $value

psalm-pure
Return values
string

        
On this page

Search results