php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70803 Serialization of same DateTime causes wrong serialized value
Submitted: 2015-10-27 17:43 UTC Modified: 2017-01-01 12:32 UTC
Votes:4
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: biozshock at gmail dot com Assigned:
Status: Duplicate Package: Class/Object related
PHP Version: 5.5.30 OS: Ubuntu LTS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: biozshock at gmail dot com
New email:
PHP Version: OS:

 

 [2015-10-27 17:43 UTC] biozshock at gmail dot com
Description:
------------
If class implements \Serializable interface and serializes same instance of \DateTime object - deserialization fails with Notice:  Notice: unserialize(): Error at offset 13 of 157 bytes in /opt/project/testme.php on line 12

Test script:
---------------
class A implements \Serializable
{
    public function serialize()
    {
        $dt = new \DateTime();
        return serialize(array($dt, serialize([$dt])));
    }

    public function unserialize($serialized)
    {
        $a = unserialize($serialized);
        unserialize($a[1]);
    }
}

$a = new A();
$s = serialize($a);
$d = unserialize($s);

Expected result:
----------------
Empty screen, no notices and proper de-serialized value

Actual result:
--------------
Notice: unserialize(): Error at offset 13 of 157 bytes in /opt/project/testme.php on line 12
And properly deserialized \DateTime object

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-01 12:32 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2017-01-01 12:32 UTC] nikic@php.net
This is a duplicate of bug #73253 (which is a duplicate of the more general bug #66052).
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Dec 02 20:03:34 2021 UTC