ValueType
class ValueType
This only defines possible value types as constants and validators static methods.
The internal PHP types returned by the gettype()
function are:
- null
- boolean
- integer
- float (double included)
- string
- array
- object
- resource
- unknown, when no other type was possible (very rare)
The class extends this list with a new type:
- callback, defined as any variable passing
the
is_callable()
function
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_CLOSURE |
Defines a closure callback (anonymous function):
|
CALLBACK_METHOD |
Defines a class' method callback:
|
CALLBACK_METHOD_STATIC |
Defines a class' static method callback:
|
CALLBACK_OBJECT |
Defines a object callback:
|
MODE_STRICT |
Defines the default behavior of internal PHP (this is the default value of the
|
BINARY_AS_BOOLEAN |
Defines the binary numbers
|
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
|
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
Returns a value type by testing it in the $order
order.
Returns a reflector for the value by testing its type in the $order
order.
Returns the type of a callback
Tests if a value is null
Tests if a value is a boolean
Tests if a value is an integer
Tests if a value is a float
Tests if a value is a double (alias of self::isFloat()
)
Tests if a value is a "real number" (alias of self::isFloat()
)
Tests if a value is a string
Tests if a value is an array
Tests if a value is an object
Tests if a value is a closure (alias of self::isCallback()
)
Tests if a value is callable (alias of self::isCallback()
)
Tests if a value is a valid callback
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.
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.
at line 255
static
int|null
getCallbackType(
callable $callback)
Returns the type of a callback
at line 294
static
bool
isNull(
mixed $value = null)
Tests if a value is null
at line 306
static
bool
isBoolean(
mixed $value = null,
int $flag = self::MODE_STRICT)
Tests if a value is a boolean
at line 321
static
bool
isInteger(
mixed $value = null,
int $flag = self::MODE_STRICT)
Tests if a value is an integer
at line 335
static
bool
isFloat(
mixed $value = null)
Tests if a value is a float
at line 347
static
bool
isDouble(
mixed $value = null)
Tests if a value is a double (alias of self::isFloat()
)
at line 359
static
bool
isRealNumber(
mixed $value = null)
Tests if a value is a "real number" (alias of self::isFloat()
)
at line 371
static
bool
isString(
mixed $value = null,
int $flag = self::MODE_STRICT)
Tests if a value is a string
at line 389
static
bool
isArray(
mixed $value = null,
int $flag = self::MODE_STRICT)
Tests if a value is an array
at line 404
static
bool
isObject(
mixed $value = null,
int $flag = self::MODE_STRICT)
Tests if a value is an object
at line 419
static
bool
isClosure(
mixed $value = null)
Tests if a value is a closure (alias of self::isCallback()
)
at line 431
static
bool
isCallable(
mixed $value = null)
Tests if a value is callable (alias of self::isCallback()
)
at line 442
static
bool
isCallback(
mixed $value = null)
Tests if a value is a valid callback
at line 453
static
bool
isResource(
mixed $value = null)
Tests if a value is a resource