On 10/24/2017 2:20 AM, Sara Golemon wrote: > https://bugs.php.net/bug.php?id=75400 is asking for a version of > JsonSerializable which doesn't involve deserializing/reserialzing > round trips when a chunk of JSON is known in advance. > > It's not terribly unreasonable IMO, but before I just writeup the RFC > as described (jsonRawSerialize taking preceedence over jsonSerialize), > I thought I'd ask for opinions on the specifics. > > In psuedo-code: > > if (is_object($obj)) { > if ($obj implements JsonRawSerializable) { > // use $obj->jsonRawSerialize() as is. > } elseif ($obj implements JsonSerializble) { > // use json_encode($obj->jsonSerialize()) > } else { > // Serialize the object's public properties as a key/value map > } > } > > Perhaps with the stipulation that if jsonRawSerialize() returns null, > we'd fallback on jsonSerialize(). Any other non-string results in an > encoding error. > > -Sara >
I agree with the others here. People often think that they can simply write the JSON on their own, but forget about the requirement for valid UTF-8 and other escaping and encoding stuff. It's better to simply not support it in the first place. -- Richard "Fleshgrinder" Fussenegger
signature.asc
Description: OpenPGP digital signature