Bug #70803 [Opn->Dup]: Serialization of same DateTime causes wrong serialized value

From: Date: Sun, 01 Jan 2017 12:32:51 +0000
Subject: Bug #70803 [Opn->Dup]: Serialization of same DateTime causes wrong serialized value
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206277@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70803&edit=1 ID: 70803 Updated by: nikic@php.net Reported by: biozshock at gmail dot com Summary: Serialization of same DateTime causes wrong serialized value -Status: Open +Status: Duplicate Type: Bug Package: Class/Object related Operating System: Ubuntu LTS PHP Version: 5.5.30 Block user comment: N Private report: N New Comment: This is a duplicate of bug #73253 (which is a duplicate of the more general bug #66052). Previous Comments: ------------------------------------------------------------------------ [2015-10-27 17:43:36] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70803&edit=1

« previous php.bugs (#206277) next »