|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80483 DateTime Object with 5-digit year can't unserialized
Submitted: 2020-12-04 08:41 UTC Modified: 2020-12-04 14:58 UTC
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: kontakt at nico-bayati dot de Assigned: cmb (profile)
Status: Duplicate Package: Date/time related
PHP Version: Irrelevant OS: Debian GNU/Linux 4.19.0
Private report: No CVE-ID: None
 [2020-12-04 08:41 UTC] kontakt at nico-bayati dot de
Maybe it is not a mistake, but I would like a consistent handling here. If 5-digit years are not desired, they should not be entered, otherwise it would be desirable that I can unserialize serialized objects, which contain 5-digit years

Tested with php 7.2, 7.3 and 7.4.

Thank you.

Test script:
$the_date = new DateTime();
$the_date->setTime(0, 0, 0);
$the_date->SetDate(20201, 01, 01);


$serialized = serialize($the_date);

Actual result:
class DateTime#1 (3) {
  public $date =>
  string(27) "20201-01-01 00:00:00.000000"
  public $timezone_type =>
  public $timezone =>
  string(13) "Europe/Berlin"
string(126) "O:8:"DateTime":3:{s:4:"date";s:27:"20201-01-01 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:13:"Europe/Berlin";}"
PHP Fatal error:  Uncaught Error: Invalid serialization data for DateTime object in /home/nico/test/unserialize.php:11
Stack trace:
#0 [internal function]: DateTime->__wakeup()
#1 /home/nico/test/unserialize.php(11): unserialize('O:8:"DateTime":...')
#2 {main}
  thrown in /home/nico/test/unserialize.php on line 11


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-04 12:51 UTC]
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2020-12-04 12:51 UTC]
This appears to be a duplicate of bug #75035.
 [2020-12-04 14:58 UTC] kontakt at nico-bayati dot de
oh, I missed the bug report, sorry about that I guess I can say goodbye to my data for now, because it hasn't been fixed for a while.

You might want to mention in the documentation that only 4-digit years are safe for serialization.

Thank you.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 13 19:01:30 2024 UTC