class ValueType

This only defines possible value types as constants and validators static methods.

The internal PHP types returned by the gettype() function are:

The class extends this list with a new type:

When the getType() method of this class tests each type one by one to find the type of the parameter, you can use some specific flags have a flexible behavior (see the documented constants of this class).

Various types of callbacks are defined to identify the "callable" type:

  • function
  • closure
  • method of instantiated object
  • static method of a class
  • object

Constants

TYPE_NULL

Defines the null type

TYPE_BOOLEAN

Defines the boolean type

TYPE_INTEGER

Defines the integer type

TYPE_FLOAT

Defines the float (double included) type

TYPE_STRING

Defines the string type

TYPE_ARRAY

Defines the array type

TYPE_OBJECT

Defines the object type

TYPE_CALLBACK

Defines the callback type

TYPE_RESOURCE

Defines the resource type

TYPE_UNKNOWN

Defines the unknown type, when no other type was possible (very rare)

CALLBACK_FUNCTION

Defines a function callback: $callback = 'functionName'

CALLBACK_CLOSURE

Defines a closure callback (anonymous function): $callback = function () use () {};

CALLBACK_METHOD

Defines a class' method callback: $callback = array('className', 'methodName')

CALLBACK_METHOD_STATIC

Defines a class' static method callback: $callback = 'className::methodName'

CALLBACK_OBJECT

Defines a object callback: $callback = array($object, 'methodName')

MODE_STRICT

Defines the default behavior of internal PHP (this is the default value of the $flag parameter of class' methods)

BINARY_AS_BOOLEAN

Defines the binary numbers 0 and 1 (and their decimal, hexadecimal, octal and binary equivalents) as booleans rather than integers

ARRAY_AS_CALLABLE

Defines a callable array as a callable rather than an array

STRING_AS_CALLABLE

Defines a callable string as a callable rather than a string

OBJECT_AS_CLOSURE

Defines a \Closure object as a closure rather than an object

NUMERIC_AS_INTEGER

Defines any numeric value as an integer

NUMERIC_AS_STRING

Defines any numeric value as a string

Properties

static array $ordered_types

Methods

static  string
getType( mixed $value, int $flag = self::MODE_STRICT, array $order = null)

Returns a value type by testing it in the $order order.

getReflector( mixed $value, int $flag = self::MODE_STRICT, array $order = null)

Returns a reflector for the value by testing its type in the $order order.

static  int|null
getCallbackType( callable $callback)

Returns the type of a callback

static  bool
isNull( mixed $value = null)

Tests if a value is null

static  bool
isBoolean( mixed $value = null, int $flag = self::MODE_STRICT)

Tests if a value is a boolean

static  bool
isInteger( mixed $value = null, int $flag = self::MODE_STRICT)

Tests if a value is an integer

static  bool
isFloat( mixed $value = null)

Tests if a value is a float

static  bool
isDouble( mixed $value = null)

Tests if a value is a double (alias of self::isFloat())

static  bool
isRealNumber( mixed $value = null)

Tests if a value is a "real number" (alias of self::isFloat())

static  bool
isString( mixed $value = null, int $flag = self::MODE_STRICT)

Tests if a value is a string

static  bool
isArray( mixed $value = null, int $flag = self::MODE_STRICT)

Tests if a value is an array

static  bool
isObject( mixed $value = null, int $flag = self::MODE_STRICT)

Tests if a value is an object

static  bool
isClosure( mixed $value = null)

Tests if a value is a closure (alias of self::isCallback())

static  bool
isCallable( mixed $value = null)

Tests if a value is callable (alias of self::isCallback())

static  bool
isCallback( mixed $value = null)

Tests if a value is a valid callback

static  bool
isResource( mixed $value = null)

Tests if a value is a resource

Details

at line 200
static string getType( mixed $value, int $flag = self::MODE_STRICT, array $order = null)

Returns a value type by testing it in the $order order.

The tests order defaults to the $ordered_types static of the class.

You can use some of the class' flags to have a flexible testing.

Parameters

mixed $value
int $flag
array $order

Return Value

string

Exceptions

InvalidArgumentException if an item of the $order array does not seem to be a valid type

at line 231
static ReflectionValueInterface getReflector( mixed $value, int $flag = self::MODE_STRICT, array $order = null)

Returns a reflector for the value by testing its type in the $order order.

See the documentation of the getType() method for more information about parameters.

Parameters

mixed $value
int $flag
array $order

Return Value

ReflectionValueInterface

at line 255
static int|null getCallbackType( callable $callback)

Returns the type of a callback

Parameters

callable $callback

Return Value

int|null

at line 294
static bool isNull( mixed $value = null)

Tests if a value is null

Parameters

mixed $value

Return Value

bool

at line 306
static bool isBoolean( mixed $value = null, int $flag = self::MODE_STRICT)

Tests if a value is a boolean

Parameters

mixed $value
int $flag

Return Value

bool

at line 321
static bool isInteger( mixed $value = null, int $flag = self::MODE_STRICT)

Tests if a value is an integer

Parameters

mixed $value
int $flag

Return Value

bool

at line 335
static bool isFloat( mixed $value = null)

Tests if a value is a float

Parameters

mixed $value

Return Value

bool

at line 347
static bool isDouble( mixed $value = null)

Tests if a value is a double (alias of self::isFloat())

Parameters

mixed $value

Return Value

bool

See also

self::isFloat()

at line 359
static bool isRealNumber( mixed $value = null)

Tests if a value is a "real number" (alias of self::isFloat())

Parameters

mixed $value

Return Value

bool

See also

self::isFloat()

at line 371
static bool isString( mixed $value = null, int $flag = self::MODE_STRICT)

Tests if a value is a string

Parameters

mixed $value
int $flag

Return Value

bool

at line 389
static bool isArray( mixed $value = null, int $flag = self::MODE_STRICT)

Tests if a value is an array

Parameters

mixed $value
int $flag

Return Value

bool

at line 404
static bool isObject( mixed $value = null, int $flag = self::MODE_STRICT)

Tests if a value is an object

Parameters

mixed $value
int $flag

Return Value

bool

at line 419
static bool isClosure( mixed $value = null)

Tests if a value is a closure (alias of self::isCallback())

Parameters

mixed $value

Return Value

bool

See also

self::isCallback()

at line 431
static bool isCallable( mixed $value = null)

Tests if a value is callable (alias of self::isCallback())

Parameters

mixed $value

Return Value

bool

See also

self::isCallback()

at line 442
static bool isCallback( mixed $value = null)

Tests if a value is a valid callback

Parameters

mixed $value

Return Value

bool

at line 453
static bool isResource( mixed $value = null)

Tests if a value is a resource

Parameters

mixed $value

Return Value

bool