php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73254 Incorrect indentation generated by json_encode() with JSON_PRETTY_PRINT
Submitted: 2016-10-05 23:28 UTC Modified: 2016-10-30 13:29 UTC
From: robo006 at gmail dot com Assigned: bukka (profile)
Status: Closed Package: JSON related
PHP Version: 7.1.0RC3 OS:
Private report: No CVE-ID: None
 [2016-10-05 23:28 UTC] robo006 at gmail dot com
Description:
------------
After call `json_encode()` that fails, all future `json_encode()` calls with `JSON_PRETTY_PRINT` generates output with incorrect indentation. 

See https://3v4l.org/reS06

Related: https://bugs.php.net/bug.php?id=66025

Test script:
---------------
<?php

echo json_encode([json_encode([1], JSON_PRETTY_PRINT)]), "\n";

$fp = fopen('php://stdin', 'r');
$data = ['a' => $fp];
echo json_encode($data), "\n";

echo json_encode([json_encode([1], JSON_PRETTY_PRINT)]), "\n";


Expected result:
----------------
["[\n    1\n]"]

["[\n    1\n]"]


Actual result:
--------------
["[\n    1\n]"]

["[\n        1\n    ]"]


Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-10-06 18:58 UTC] bukka@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: bukka
 [2016-10-30 13:29 UTC] bukka@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Feb 23 17:01:28 2020 UTC