php.net |  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
Votes:1
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
Description:
------------
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:
---------------
<?php
  
$the_date = new DateTime();
$the_date->setTime(0, 0, 0);
$the_date->SetDate(20201, 01, 01);

var_dump($the_date);

$serialized = serialize($the_date);
var_dump($serialized);
var_dump(unserialize($serialized));

Actual result:
--------------
/home/nico/test/unserialize.php:7:
class DateTime#1 (3) {
  public $date =>
  string(27) "20201-01-01 00:00:00.000000"
  public $timezone_type =>
  int(3)
  public $timezone =>
  string(13) "Europe/Berlin"
}
/home/nico/test/unserialize.php:10:
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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-04 12:51 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2020-12-04 12:51 UTC] cmb@php.net
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: Mon Dec 30 14:01:28 2024 UTC