Serializer
class Serializer (View source)
Serializer class.
Methods
static mixed
decode(string $value)
Decodes the given value using JSON standard.
static string
encode(mixed $value)
Encodes the given value using JSON standard.
static string
serialize(mixed $variable)
Returns a string representation of the given variable.
static mixed
unserialize(string $variable, string|null $cast = null)
Returns the passed variable and applies the given cast to it if specified.
Details
static mixed
decode(string $value)
Decodes the given value using JSON standard.
static string
encode(mixed $value)
Encodes the given value using JSON standard.
static string
serialize(mixed $variable)
Returns a string representation of the given variable.
The variable will be stringified as follows:
null
-> As JSON null (null
).boolean
-> As JSON boolean (true
orfalse
).integer
-> As JSON number (123
).float
-> As JSON number (1.5
).string
-> As JSON string ("string"
).array
-> As JSON array or object ([1, "2", "Three"]
or{"one": 1, "two": "2", "three": "Three"}
).object
-> As JSON object ({"property": "value"}
) or the result of stringifing if the object implements__toString()
.
NOTE: This method works in conjunction with self::unserialize()
.
static mixed
unserialize(string $variable, string|null $cast = null)
Returns the passed variable and applies the given cast to it if specified.
Available casts are:
null
boolean
orbool
integer
orint
float
ordouble
string
array
object
NOTE: Unknown casts will return the passed variable.
NOTE: This method works in conjunction with self::serialize()
.