Open Tigrov opened 11 months ago
jsonSerialize()
PHP documentation mentions: Returns data which can be serialized by json_encode()
json_encode()
processObject() should return the result of jsonSerialize() without processing:
processObject()
private static function processObject(object $data) { if ($data instanceof JsonSerializable) { return $data->jsonSerialize(); } ... }
But this will break BC.
If it is requered to pre-process data for JsonSerializable, this should be done inside jsonSerialize():
JsonSerializable
class SomeClass implements JsonSerializable { ... public function jsonSerialize(): mixed { return Json:process($this->data); } ... }
About
jsonSerialize()
PHP documentation mentions: Returns data which can be serialized by
json_encode()
processObject()
should return the result ofjsonSerialize()
without processing:But this will break BC.
If it is requered to pre-process data for
JsonSerializable
, this should be done insidejsonSerialize()
: