Bug #80483 [NEW]: DateTime Object with 5-digit year can't unserialized

From: Date: Fri, 04 Dec 2020 08:41:00 +0000
Subject: Bug #80483 [NEW]: DateTime Object with 5-digit year can't unserialized
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230831@lists.php.net to get a copy of this message
From:             kontakt at nico-bayati dot de
Operating system: Debian GNU/Linux 4.19.0
PHP version:      Irrelevant
Package:          Date/time related
Bug Type:         Bug
Bug description:DateTime Object with 5-digit year can't unserialized

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

-- 
Edit bug report at https://bugs.php.net/bug.php?id=80483&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=80483&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=80483&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=80483&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=80483&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=80483&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=80483&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=80483&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=80483&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=80483&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=80483&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80483&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=80483&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=80483&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=80483&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=80483&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=80483&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=80483&r=mysqlcfg


Thread (3 messages)

« previous php.bugs (#230831) next »