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
 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 03:01:29 2024 UTC