-
Notifications
You must be signed in to change notification settings - Fork 0
jsonToSerial
Corey Avis edited this page Sep 23, 2026
·
2 revisions
Safely converts a valid JSON string directly into a PHP serialized string.
jsonToSerial(string $json): string
json (string) : The JSON string to decode and serialize.
(string)
: Returns a PHP serialized string representation of the decoded data structure on success.
: Returns a serialized empty array (a:0:{}) if the JSON string is malformed or decodes into a non-array scalar value.
📌 Chains
jsonToArrayandarrayToSerialto safely normalize input data prior to serialization.
$cphp->jsonToSerial('{"id":10,"user":"name","active":true}');
// Result: a:3:{s:2:"id";i:10;s:4:"user";s:4:"name";s:6:"active";b:1;}
$cphp->jsonToSerial('{bad_json}');
// Result: a:0:{} (Logs a warning)
- Triggers a warning via underlying
jsonToArrayif there was an issue decoding the JSON.
jsonToArray | jsonToObject | serialToJson
Home | CoreyPHP | Conversion