json
Table of Contents
Functions
- deepJsonSerialize() : mixed
- Recursively serialize all JsonSerializable values within an array or object.
- getJsonType() : string
- Get JSON type of a PHP value.
- isValidJsonDecodeFlags() : bool
- Checks whether a given integer value is a valid combination of `json_decode()` option flags.
- isValidJsonEncodeFlags() : bool
- Checks whether a given integer value is a valid combination of `json_encode()` option flags.
Functions
deepJsonSerialize()
Recursively serialize all JsonSerializable values within an array or object.
deepJsonSerialize(mixed $value[, int $currentDepth = 0 ]) : mixed
This function traverses arrays and objects at any depth, and whenever it finds a value that implements JsonSerializable, it calls jsonSerialize() on it.
Parameters
- $value : mixed
-
The value to serialize.
- $currentDepth : int = 0
-
Internal recursion counter (default 0).
Tags
Return values
mixed —The value with all JsonSerializable elements serialized.
getJsonType()
Get JSON type of a PHP value.
getJsonType(mixed $value[, string $default = 'unknown' ]) : string
Parameters
- $value : mixed
-
The value to evaluates.
- $default : string = 'unknown'
-
The default return value if the type is not a valid JSON type.
Tags
Return values
stringisValidJsonDecodeFlags()
Checks whether a given integer value is a valid combination of `json_decode()` option flags.
isValidJsonDecodeFlags(int $flags) : bool
The function compares the provided bitmask against the list of officially supported JSON_*
constants for json_decode() in the current PHP version.
Note: PHP itself does not validate unknown flag bits in
json_decode()— they are simply ignored. This helper ensures stricter validation.
Parameters
- $flags : int
-
One or more
JSON_*constants combined with bitwise OR (|).
Tags
Return values
bool —Returns true if the given flags are a valid combination of json_decode() options,
false otherwise.
isValidJsonEncodeFlags()
Checks whether a given integer value is a valid combination of `json_encode()` option flags.
isValidJsonEncodeFlags(int $flags) : bool
The function compares the provided bitmask against the list of officially supported JSON_*
constants in the current PHP version. If any unsupported bits are set, the function will return false.
Note: PHP itself does not validate unknown flag bits in
json_encode()— they are simply ignored. This helper ensures stricter validation.
Parameters
- $flags : int
-
One or more
JSON_*constants combined with bitwise OR (|).
Tags
Return values
bool —Returns true if the given flags are a valid combination of json_encode() options,
false otherwise.