Type
: string
in package
uses
EnumDynamicity
Possible types as returned by {@see gettype()}.
Table of Contents
Cases
- Array = self::ARRAY
- An array in PHP is actually an ordered map. A map is a type that associates values to keys.
- Boolean = self::BOOLEAN
- The boolean type only has two values and is used to express a truth value. It can be either `true` or `false`.
- ClosedResource = self::CLOSED_RESOURCE
- Closed resources are reported as "resource (closed)".
- Float = self::FLOAT
- A "float" is a floating point number, also known as a "double", or "real number".
- Integer = self::INTEGER
- An integer is a number of the set ℤ = {..., -2, -1, 0, 1, 2, ...}.
- Null = self::NULL
- The null type is PHP's unit type, i.e. it has only one value: NULL.
- Object = self::OBJECT
- An object is an instance of a class or an enumeration.
- Resource = self::RESOURCE
- A resource is a special variable, holding a reference to an external resource. Resources are created and used by special functions.
- String = self::STRING
- A string is a series of characters where a character is the same as a byte.
- Unknown = self::UNKNOWN
- A value of an unknown type.
Methods
- is() : bool
- Checks whether the type of the provided value matches this Type.
- of() : mixed
- Returns the Type instance of the provided value.
- tryOf() : self|null
- Returns the Type of the provided value. If the value is of an unknown type, it will return NULL.
Cases
Null
The null type is PHP's unit type, i.e. it has only one value: NULL.
Undefined and unset() variables will
also resolve to the value null
.
Boolean
The boolean type only has two values and is used to express a truth value. It can be either `true` or `false`.
Integer
An integer is a number of the set ℤ = {..., -2, -1, 0, 1, 2, ...}.
Float
A "float" is a floating point number, also known as a "double", or "real number".
String
A string is a series of characters where a character is the same as a byte.
Array
An array in PHP is actually an ordered map. A map is a type that associates values to keys.
This type is optimized for several different uses; it can be treated
as an array, list (vector), hash table (an implementation of a map),
dictionary, collection, stack, queue, and probably more. As
array values can be other
array
s, trees and multidimensional array
s are also possible.
Object
An object is an instance of a class or an enumeration.
Resource
A resource is a special variable, holding a reference to an external resource. Resources are created and used by special functions.
See the appendix for a listing of all these functions and the corresponding resource types.
See also the get_resource_type() function.
ClosedResource
Closed resources are reported as "resource (closed)".
Unknown
A value of an unknown type.
Methods
is()
Checks whether the type of the provided value matches this Type.
public
is(mixed $value) : bool
Parameters
- $value : mixed
-
The value to check.
Return values
bool —Returns true
if value matches this Type, false
otherwise.
of()
Returns the Type instance of the provided value.
public
static of(mixed $value) : mixed
Parameters
- $value : mixed
-
The value for which to deduce the type.
Return values
mixed —A Type case instance.
tryOf()
Returns the Type of the provided value. If the value is of an unknown type, it will return NULL.
public
static tryOf(mixed $value) : self|null
Parameters
- $value : mixed
-
The value for which to try to deduce the type.
Return values
self|null —A Type case instance, or null
if value is of an unknown type.