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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
38 - 1 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 05:01:28 2024 UTC