Req #75400 [NEW]: Already As JSON

From: Date: Tue, 17 Oct 2017 19:55:13 +0000
Subject: Req #75400 [NEW]: Already As JSON
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211766@lists.php.net to get a copy of this message
From: jwalton at aretehs dot com Operating system: Any PHP version: 7.0.24 Package: JSON related Bug Type: Feature/Change Request Bug description:Already As JSON 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 bug report at https://bugs.php.net/bug.php?id=75400&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75400&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75400&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75400&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=75400&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=75400&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=75400&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=75400&r=needscript Try newer version: https://bugs.php.net/fix.php?id=75400&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=75400&r=support Expected behavior: https://bugs.php.net/fix.php?id=75400&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=75400&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=75400&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=75400&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75400&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=75400&r=dst IIS Stability: https://bugs.php.net/fix.php?id=75400&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=75400&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=75400&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=75400&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=75400&r=mysqlcfg

« previous php.bugs (#211766) next »