xref: /PHP-8.1/ext/date/tests/bug52113.phpt (revision 1270e500)
1--TEST--
2Bug #52113 (Seg fault while creating (by unserialization) DatePeriod)
3--INI--
4date.timezone=UTC
5--FILE--
6<?php
7$start = new DateTime('2003-01-02 08:00:00');
8$end = new DateTime('2003-01-02 12:00:00');
9$diff = $start->diff($end);
10$p = new DatePeriod($start, $diff, 2);
11$diff_s = serialize($diff);
12var_dump($diff, $diff_s);
13var_export($diff);
14
15$diff_un = unserialize($diff_s);
16$p = new DatePeriod($start, $diff_un, 2);
17var_dump($diff_un, $p);
18
19$unser = DateInterval::__set_state(array(
20   'y' => 7,
21   'm' => 6,
22   'd' => 5,
23   'h' => 4,
24   'i' => 3,
25   's' => 2,
26   'f' => 0.876543,
27   'invert' => 1,
28   'days' => 2400,
29));
30
31$p = new DatePeriod($start, $diff_un, 2);
32var_dump($unser, $p);
33
34?>
35--EXPECTF--
36object(DateInterval)#%d (16) {
37  ["y"]=>
38  int(0)
39  ["m"]=>
40  int(0)
41  ["d"]=>
42  int(0)
43  ["h"]=>
44  int(4)
45  ["i"]=>
46  int(0)
47  ["s"]=>
48  int(0)
49  ["f"]=>
50  float(0)
51  ["weekday"]=>
52  int(0)
53  ["weekday_behavior"]=>
54  int(0)
55  ["first_last_day_of"]=>
56  int(0)
57  ["invert"]=>
58  int(0)
59  ["days"]=>
60  int(0)
61  ["special_type"]=>
62  int(0)
63  ["special_amount"]=>
64  int(0)
65  ["have_weekday_relative"]=>
66  int(0)
67  ["have_special_relative"]=>
68  int(0)
69}
70string(332) "O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h";i:4;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";i:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}"
71DateInterval::__set_state(array(
72   'y' => 0,
73   'm' => 0,
74   'd' => 0,
75   'h' => 4,
76   'i' => 0,
77   's' => 0,
78   'f' => 0.0,
79   'weekday' => 0,
80   'weekday_behavior' => 0,
81   'first_last_day_of' => 0,
82   'invert' => 0,
83   'days' => 0,
84   'special_type' => 0,
85   'special_amount' => 0,
86   'have_weekday_relative' => 0,
87   'have_special_relative' => 0,
88))object(DateInterval)#%d (16) {
89  ["y"]=>
90  int(0)
91  ["m"]=>
92  int(0)
93  ["d"]=>
94  int(0)
95  ["h"]=>
96  int(4)
97  ["i"]=>
98  int(0)
99  ["s"]=>
100  int(0)
101  ["f"]=>
102  float(0)
103  ["weekday"]=>
104  int(0)
105  ["weekday_behavior"]=>
106  int(0)
107  ["first_last_day_of"]=>
108  int(0)
109  ["invert"]=>
110  int(0)
111  ["days"]=>
112  int(0)
113  ["special_type"]=>
114  int(0)
115  ["special_amount"]=>
116  int(0)
117  ["have_weekday_relative"]=>
118  int(0)
119  ["have_special_relative"]=>
120  int(0)
121}
122object(DatePeriod)#%d (6) {
123  ["start"]=>
124  object(DateTime)#%d (3) {
125    ["date"]=>
126    string(26) "2003-01-02 08:00:00.000000"
127    ["timezone_type"]=>
128    int(3)
129    ["timezone"]=>
130    string(3) "UTC"
131  }
132  ["current"]=>
133  NULL
134  ["end"]=>
135  NULL
136  ["interval"]=>
137  object(DateInterval)#%d (16) {
138    ["y"]=>
139    int(0)
140    ["m"]=>
141    int(0)
142    ["d"]=>
143    int(0)
144    ["h"]=>
145    int(4)
146    ["i"]=>
147    int(0)
148    ["s"]=>
149    int(0)
150    ["f"]=>
151    float(0)
152    ["weekday"]=>
153    int(0)
154    ["weekday_behavior"]=>
155    int(0)
156    ["first_last_day_of"]=>
157    int(0)
158    ["invert"]=>
159    int(0)
160    ["days"]=>
161    int(0)
162    ["special_type"]=>
163    int(0)
164    ["special_amount"]=>
165    int(0)
166    ["have_weekday_relative"]=>
167    int(0)
168    ["have_special_relative"]=>
169    int(0)
170  }
171  ["recurrences"]=>
172  int(3)
173  ["include_start_date"]=>
174  bool(true)
175}
176object(DateInterval)#%d (16) {
177  ["y"]=>
178  int(7)
179  ["m"]=>
180  int(6)
181  ["d"]=>
182  int(5)
183  ["h"]=>
184  int(4)
185  ["i"]=>
186  int(3)
187  ["s"]=>
188  int(2)
189  ["f"]=>
190  float(0.876543)
191  ["weekday"]=>
192  int(-1)
193  ["weekday_behavior"]=>
194  int(-1)
195  ["first_last_day_of"]=>
196  int(-1)
197  ["invert"]=>
198  int(1)
199  ["days"]=>
200  int(2400)
201  ["special_type"]=>
202  int(0)
203  ["special_amount"]=>
204  int(-1)
205  ["have_weekday_relative"]=>
206  int(0)
207  ["have_special_relative"]=>
208  int(0)
209}
210object(DatePeriod)#%d (6) {
211  ["start"]=>
212  object(DateTime)#%d (3) {
213    ["date"]=>
214    string(26) "2003-01-02 08:00:00.000000"
215    ["timezone_type"]=>
216    int(3)
217    ["timezone"]=>
218    string(3) "UTC"
219  }
220  ["current"]=>
221  NULL
222  ["end"]=>
223  NULL
224  ["interval"]=>
225  object(DateInterval)#%d (16) {
226    ["y"]=>
227    int(0)
228    ["m"]=>
229    int(0)
230    ["d"]=>
231    int(0)
232    ["h"]=>
233    int(4)
234    ["i"]=>
235    int(0)
236    ["s"]=>
237    int(0)
238    ["f"]=>
239    float(0)
240    ["weekday"]=>
241    int(0)
242    ["weekday_behavior"]=>
243    int(0)
244    ["first_last_day_of"]=>
245    int(0)
246    ["invert"]=>
247    int(0)
248    ["days"]=>
249    int(0)
250    ["special_type"]=>
251    int(0)
252    ["special_amount"]=>
253    int(0)
254    ["have_weekday_relative"]=>
255    int(0)
256    ["have_special_relative"]=>
257    int(0)
258  }
259  ["recurrences"]=>
260  int(3)
261  ["include_start_date"]=>
262  bool(true)
263}
264