Bug #66025 [Opn]: Indent wrong when json_encode() called from jsonSerialize function

From: Date: Sun, 15 May 2016 14:53:23 +0000
Subject: Bug #66025 [Opn]: Indent wrong when json_encode() called from jsonSerialize function
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201105@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66025&edit=1 ID: 66025 Updated by: bukka@php.net Reported by: pleasestand at live dot com Summary: Indent wrong when json_encode() called from jsonSerialize function Status: Open Type: Bug Package: JSON related PHP Version: master-Git-2013-11-03 (Git) -Assigned To: +Assigned To: bukka Block user comment: N Private report: N New Comment: The bug is caused by the fact that globals are used for encoder depth. I plan to introduce a separate context for each encoder run which will fix this and couple of others bugs related to globals in json encoding. This won't happen before 7.1 Previous Comments: ------------------------------------------------------------------------ [2015-02-13 01:45:28] encryptio at gmail dot com I'm hitting this in production at my workplace; specifically, when json_encode causes the interpereter to run out of memory and abort requests in mod_php, php_json_encode_array doesn't have a chance to decrement the encoder_depth variable, leaving a thread-local inconsistency in the interpereter. ------------------------------------------------------------------------ [2013-11-03 13:19:54] pleasestand at live dot com Description: ------------ This is because the current indent is stored in a variable JSON_G(encoder_depth), which is shared between json_encode() calls. Test script: --------------- <?php class Foo implements JsonSerializable { public function jsonSerialize() { return json_encode([1], JSON_PRETTY_PRINT); } } echo json_encode([new Foo]), "\n"; Expected result: ---------------- ["[\n 1\n]"] Actual result: -------------- ["[\n 1\n ]"] ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66025&edit=1

« previous php.bugs (#201105) next »