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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: robo006 at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

Pull requests:

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: Wed Oct 16 07:01:27 2024 UTC