|  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
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.
Block user comment
Status: Assign to:
Bug Type:
From: biozshock at gmail dot com
New email:
PHP Version: OS:


 [2015-10-27 17:43 UTC] biozshock at gmail dot com
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);

$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


Add a Patch

Pull Requests

Add a Pull Request


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