php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72069 Behavior \JsonSerializable different from json_encode
Submitted: 2016-04-21 15:19 UTC Modified: -
From: dpetrov at dev dot football dot com Assigned:
Status: Closed Package: JSON related
PHP Version: 7.0.5 OS: centos 7
Private report: No CVE-ID: None
 [2016-04-21 15:19 UTC] dpetrov at dev dot football dot com
Description:
------------
Behavior \JsonSerializable different from json_encode if contains json_decode(null, true) in PHP 7.

Test script:
---------------
https://3v4l.org/UraSC

<?php

$result = json_encode(['end' => json_decode(null, true)]);
var_dump($result);

class A implements \JsonSerializable
{
    function jsonSerialize()
    {
        return ['end' => json_decode(null, true)];
    }
}
$a = new A();
$toJsonData = $a->jsonSerialize();
$result = json_encode($a);
var_dump($result);

$result = json_encode($toJsonData);
var_dump($result);


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-23 04:42 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=589d0e0f187ff82f90110057f624c958f0d3ec86
Log: Fixed bug #72069 (Behavior \JsonSerializable different from json_encode)
 [2016-04-23 04:42 UTC] laruence@php.net
-Status: Open +Status: Closed
 [2016-07-20 11:31 UTC] davey@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=589d0e0f187ff82f90110057f624c958f0d3ec86
Log: Fixed bug #72069 (Behavior \JsonSerializable different from json_encode)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 11 10:01:27 2024 UTC