xref: /PHP-8.0/ext/date/tests/bug53437.phpt (revision a555cc0b)
1--TEST--
2Bug #53437 (Crash when using unserialized DatePeriod instance), variation 1
3--FILE--
4<?php
5$dp = new DatePeriod(new DateTime('2010-01-01 UTC'), new DateInterval('P1D'), 2);
6
7echo "Original:\r\n";
8foreach($dp as $dt) {
9        echo $dt->format('Y-m-d H:i:s')."\r\n";
10}
11echo "\r\n";
12var_dump($dp);
13
14$ser = serialize($dp); // $ser is: O:10:"DatePeriod":0:{}
15
16// Create dangerous instance
17$dpu = unserialize($ser); // $dpu has invalid values???
18var_dump($dpu);
19
20echo "Unserialized:\r\n";
21foreach($dpu as $dt) {
22        echo $dt->format('Y-m-d H:i:s')."\r\n";
23}
24?>
25--EXPECTF--
26Original:
272010-01-01 00:00:00
282010-01-02 00:00:00
292010-01-03 00:00:00
30
31object(DatePeriod)#%d (6) {
32  ["start"]=>
33  object(DateTime)#%d (3) {
34    ["date"]=>
35    string(26) "2010-01-01 00:00:00.000000"
36    ["timezone_type"]=>
37    int(3)
38    ["timezone"]=>
39    string(3) "UTC"
40  }
41  ["current"]=>
42  object(DateTime)#%d (3) {
43    ["date"]=>
44    string(26) "2010-01-04 00:00:00.000000"
45    ["timezone_type"]=>
46    int(3)
47    ["timezone"]=>
48    string(3) "UTC"
49  }
50  ["end"]=>
51  NULL
52  ["interval"]=>
53  object(DateInterval)#%d (16) {
54    ["y"]=>
55    int(0)
56    ["m"]=>
57    int(0)
58    ["d"]=>
59    int(1)
60    ["h"]=>
61    int(0)
62    ["i"]=>
63    int(0)
64    ["s"]=>
65    int(0)
66    ["f"]=>
67    float(0)
68    ["weekday"]=>
69    int(0)
70    ["weekday_behavior"]=>
71    int(0)
72    ["first_last_day_of"]=>
73    int(0)
74    ["invert"]=>
75    int(0)
76    ["days"]=>
77    bool(false)
78    ["special_type"]=>
79    int(0)
80    ["special_amount"]=>
81    int(0)
82    ["have_weekday_relative"]=>
83    int(0)
84    ["have_special_relative"]=>
85    int(0)
86  }
87  ["recurrences"]=>
88  int(3)
89  ["include_start_date"]=>
90  bool(true)
91}
92object(DatePeriod)#%d (6) {
93  ["start"]=>
94  object(DateTime)#%d (3) {
95    ["date"]=>
96    string(26) "2010-01-01 00:00:00.000000"
97    ["timezone_type"]=>
98    int(3)
99    ["timezone"]=>
100    string(3) "UTC"
101  }
102  ["current"]=>
103  object(DateTime)#%d (3) {
104    ["date"]=>
105    string(26) "2010-01-04 00:00:00.000000"
106    ["timezone_type"]=>
107    int(3)
108    ["timezone"]=>
109    string(3) "UTC"
110  }
111  ["end"]=>
112  NULL
113  ["interval"]=>
114  object(DateInterval)#%d (16) {
115    ["y"]=>
116    int(0)
117    ["m"]=>
118    int(0)
119    ["d"]=>
120    int(1)
121    ["h"]=>
122    int(0)
123    ["i"]=>
124    int(0)
125    ["s"]=>
126    int(0)
127    ["f"]=>
128    float(0)
129    ["weekday"]=>
130    int(0)
131    ["weekday_behavior"]=>
132    int(0)
133    ["first_last_day_of"]=>
134    int(0)
135    ["invert"]=>
136    int(0)
137    ["days"]=>
138    bool(false)
139    ["special_type"]=>
140    int(0)
141    ["special_amount"]=>
142    int(0)
143    ["have_weekday_relative"]=>
144    int(0)
145    ["have_special_relative"]=>
146    int(0)
147  }
148  ["recurrences"]=>
149  int(3)
150  ["include_start_date"]=>
151  bool(true)
152}
153Unserialized:
1542010-01-01 00:00:00
1552010-01-02 00:00:00
1562010-01-03 00:00:00
157