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

From: Date: Sun, 03 Nov 2013 13:19:54 +0000
Subject: Bug #66025 [NEW]: Indent wrong when json_encode() called from jsonSerialize function
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182575@lists.php.net to get a copy of this message
From:             pleasestand at live dot com
Operating system: 
PHP version:      master-Git-2013-11-03 (Git)
Package:          JSON related
Bug Type:         Bug
Bug description:Indent wrong when json_encode() called from jsonSerialize function

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 bug report at https://bugs.php.net/bug.php?id=66025&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=66025&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=66025&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=66025&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=66025&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=66025&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=66025&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=66025&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=66025&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=66025&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=66025&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=66025&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=66025&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=66025&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66025&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=66025&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=66025&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=66025&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66025&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=66025&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=66025&r=mysqlcfg



Thread (5 messages)

« previous php.bugs (#182575) next »