Re: json(Raw)Serializable?

From: Date: Tue, 24 Oct 2017 17:16:05 +0000
Subject: Re: json(Raw)Serializable?
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-100936@lists.php.net to get a copy of this message
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

Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
« previous php.internals (#100936) next »