php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39821 Unable to Serialize and then Unserialize a PHP DateTime Object
Submitted: 2006-12-13 20:32 UTC Modified: 2009-03-10 23:57 UTC
From: php at michaelho dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.0 OS: Mac OS X 10.4.7
Private report: No CVE-ID: None
 [2006-12-13 20:32 UTC] php at michaelho dot com
Description:
------------
Attempts to use a DateTime object that has been serialized/unserialized produces an error.

Reproduce code:
---------------
<?php
	$dttNow = new DateTime('now');
	print $dttNow->format(DateTime::ISO8601) . '<br/>';
	$strSerialized = serialize($dttNow);
	
	$dttRestored = unserialize($strSerialized);
	print $dttRestored->format(DateTime::ISO8601) . '<br/>';
?>

Expected result:
----------------
2006-12-13T12:26:39-0800
2006-12-13T12:26:39-0800

Actual result:
--------------
2006-12-13T12:26:39-0800

Warning: DateTime::format() [function.DateTime-format]: The DateTime object has not been correctly initialized by its constructor in /home/wcc/wwwroot/test.php on line 7

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-17 14:25 UTC] bjori@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

From www.php.net/serialize: "It is not possible to 
serialize PHP built-in objects."
 [2009-03-10 23:57 UTC] pajoye@php.net
Implemented in 5.3.0, see #41334
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 14:01:31 2024 UTC