1--TEST--
2Tests for DateTime[Immutable]::createFromTimestamp 32bit variant
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
6?>
7--INI--
8date.timezone=Europe/London
9--FILE--
10<?php
11
12$timestamps = array(
13    PHP_INT_MAX,
14    PHP_INT_MIN,
15    PHP_INT_MAX + 0.5,
16    PHP_INT_MIN + 0.5,
17    PHP_INT_MAX - 0.5,
18    PHP_INT_MIN - 0.5,
19    PHP_INT_MAX + 1024.0,
20    PHP_INT_MIN - 1025.0,
21);
22
23foreach ($timestamps as $ts) {
24    echo 'DateTime::createFromTimestamp(' . var_export($ts, true) . '): ';
25    try {
26        var_dump(DateTime::createFromTimestamp($ts));
27    } catch (Throwable $e) {
28        echo get_class($e) . ': ' . $e->getMessage() . "\n";
29    }
30
31    echo 'DateTimeImmutable::createFromTimestamp(' . var_export($ts, true) . '): ';
32    try {
33        var_dump(DateTimeImmutable::createFromTimestamp($ts));
34    } catch (Throwable $e) {
35        echo get_class($e) . ': ' . $e->getMessage() . "\n";
36    }
37}
38
39?>
40--EXPECTF--
41DateTime::createFromTimestamp(2147483647): object(DateTime)#%d (3) {
42  ["date"]=>
43  string(26) "2038-01-19 03:14:07.000000"
44  ["timezone_type"]=>
45  int(1)
46  ["timezone"]=>
47  string(6) "+00:00"
48}
49DateTimeImmutable::createFromTimestamp(2147483647): object(DateTimeImmutable)#%d (3) {
50  ["date"]=>
51  string(26) "2038-01-19 03:14:07.000000"
52  ["timezone_type"]=>
53  int(1)
54  ["timezone"]=>
55  string(6) "+00:00"
56}
57DateTime::createFromTimestamp(-2147483647-1): object(DateTime)#%d (3) {
58  ["date"]=>
59  string(26) "1901-12-13 20:45:52.000000"
60  ["timezone_type"]=>
61  int(1)
62  ["timezone"]=>
63  string(6) "+00:00"
64}
65DateTimeImmutable::createFromTimestamp(-2147483647-1): object(DateTimeImmutable)#%d (3) {
66  ["date"]=>
67  string(26) "1901-12-13 20:45:52.000000"
68  ["timezone_type"]=>
69  int(1)
70  ["timezone"]=>
71  string(6) "+00:00"
72}
73DateTime::createFromTimestamp(2147483647.5): object(DateTime)#%d (3) {
74  ["date"]=>
75  string(26) "2038-01-19 03:14:07.500000"
76  ["timezone_type"]=>
77  int(1)
78  ["timezone"]=>
79  string(6) "+00:00"
80}
81DateTimeImmutable::createFromTimestamp(2147483647.5): object(DateTimeImmutable)#%d (3) {
82  ["date"]=>
83  string(26) "2038-01-19 03:14:07.500000"
84  ["timezone_type"]=>
85  int(1)
86  ["timezone"]=>
87  string(6) "+00:00"
88}
89DateTime::createFromTimestamp(-2147483647.5): object(DateTime)#%d (3) {
90  ["date"]=>
91  string(26) "1901-12-13 20:45:52.500000"
92  ["timezone_type"]=>
93  int(1)
94  ["timezone"]=>
95  string(6) "+00:00"
96}
97DateTimeImmutable::createFromTimestamp(-2147483647.5): object(DateTimeImmutable)#%d (3) {
98  ["date"]=>
99  string(26) "1901-12-13 20:45:52.500000"
100  ["timezone_type"]=>
101  int(1)
102  ["timezone"]=>
103  string(6) "+00:00"
104}
105DateTime::createFromTimestamp(2147483646.5): object(DateTime)#%d (3) {
106  ["date"]=>
107  string(26) "2038-01-19 03:14:06.500000"
108  ["timezone_type"]=>
109  int(1)
110  ["timezone"]=>
111  string(6) "+00:00"
112}
113DateTimeImmutable::createFromTimestamp(2147483646.5): object(DateTimeImmutable)#%d (3) {
114  ["date"]=>
115  string(26) "2038-01-19 03:14:06.500000"
116  ["timezone_type"]=>
117  int(1)
118  ["timezone"]=>
119  string(6) "+00:00"
120}
121DateTime::createFromTimestamp(-2147483648.5): DateRangeError: DateTime::createFromTimestamp(): Argument #1 ($timestamp) must be a finite number between -2147483648 and 2147483647.999999, -2.14748e+9 given
122DateTimeImmutable::createFromTimestamp(-2147483648.5): DateRangeError: DateTimeImmutable::createFromTimestamp(): Argument #1 ($timestamp) must be a finite number between -2147483648 and 2147483647.999999, -2.14748e+9 given
123DateTime::createFromTimestamp(2147484671.0): DateRangeError: DateTime::createFromTimestamp(): Argument #1 ($timestamp) must be a finite number between -2147483648 and 2147483647.999999, 2.14748e+9 given
124DateTimeImmutable::createFromTimestamp(2147484671.0): DateRangeError: DateTimeImmutable::createFromTimestamp(): Argument #1 ($timestamp) must be a finite number between -2147483648 and 2147483647.999999, 2.14748e+9 given
125DateTime::createFromTimestamp(-2147484673.0): DateRangeError: DateTime::createFromTimestamp(): Argument #1 ($timestamp) must be a finite number between -2147483648 and 2147483647.999999, -2.14748e+9 given
126DateTimeImmutable::createFromTimestamp(-2147484673.0): DateRangeError: DateTimeImmutable::createFromTimestamp(): Argument #1 ($timestamp) must be a finite number between -2147483648 and 2147483647.999999, -2.14748e+9 given
127