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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
2 + 13 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 15:01:29 2024 UTC