Bug #66025 [Com]: Indent wrong when json_encode() called from jsonSerialize function
Edit report at https://bugs.php.net/bug.php?id=66025&edit=1
ID: 66025
Comment by: encryptio at gmail dot com
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)
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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
Thread (5 messages)