xref: /PHP-8.3/ext/date/tests/bug75035.phpt (revision d002a0d8)
1--TEST--
2Bug #75035 (Datetime fails to unserialize "extreme" dates)
3--INI--
4date.timezone=UTC
5--FILE--
6<?php
7var_dump('PHP version', PHP_VERSION);
8
9foreach ([PHP_INT_MIN, PHP_INT_MAX] as $extreme) {
10    $i = 64;
11    while ($i-- > 1) {
12        $d = new DateTime('@' . ($extreme >> $i));
13        $s = serialize($d);
14        try {
15            $u = unserialize($s);
16        } catch (Error $e) {
17            $u = "failed unserialization: " . $e->getMessage() . ' : ' . $s;
18        }
19        $original = $d->format('Y-m-d H:i:s');
20        $serializedUnserialized = is_string($u) ? $u : $u->format('Y-m-d H:i:s');
21        if ($original !== $serializedUnserialized) {
22            var_dump('[' . ($extreme >> $i) . '] ' . $original . ' => ' . $serializedUnserialized);
23        }
24    }
25}
26?>
27--EXPECTF--
28string(11) "PHP version"
29string(%d) "%s"
30