Req #75400 [Opn->Ana]: Already As JSON

From: Date: Mon, 23 Oct 2017 23:57:39 +0000
Subject: Req #75400 [Opn->Ana]: Already As JSON
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211863@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75400&edit=1 ID: 75400 Updated by: pollita@php.net Reported by: jwalton at aretehs dot com Summary: Already As JSON -Status: Open +Status: Analyzed Type: Feature/Change Request Package: JSON related Operating System: Any PHP Version: 7.0.24 Block user comment: N Private report: N New Comment: That's not unreasonable. I'll propose it to the list and see about getting it into 7.3. Previous Comments: ------------------------------------------------------------------------ [2017-10-17 19:55:11] jwalton at aretehs dot com Description: ------------ Ability for an object to specify that it already is encoded. Example, data returned from a database may already be in JSON format, so it seems pretty pointless to decode it, only to re-encode it in another object. It could be as simple as adding a new function maybe, like, jsonRawSerialize() or something. My issue is that sometimes the the json is over 200k and it adds quite a bit of extra CPU cycles. Test script: --------------- // Example class MyJSON { public function jsonSerialize() { return '{"myobject":true}'; } } print json_encode((object)[ "result" => new MyJSON() ]); // should print // {"result"=>{"myobject"=>true}} // //right now you have to do class MyJSON2 { public function jsonSerialize() { return json_decode('{"myobject":true}'); } } print json_encode((object)[ "result" => new MyJSON2() ]); ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75400&edit=1

« previous php.bugs (#211863) next »