xref: /PHP-8.2/ext/date/tests/bug52113.phpt (revision 4f1b8f48)
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 (%d) {
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  ["invert"]=>
52  int(0)
53  ["days"]=>
54  int(0)
55  ["from_string"]=>
56  bool(false)
57}
58string(164) "O:12:"DateInterval":10:{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:6:"invert";i:0;s:4:"days";i:0;s:11:"from_string";b:0;}"
59\DateInterval::__set_state(array(
60   'y' => 0,
61   'm' => 0,
62   'd' => 0,
63   'h' => 4,
64   'i' => 0,
65   's' => 0,
66   'f' => 0.0,
67   'invert' => 0,
68   'days' => 0,
69   'from_string' => false,
70))object(DateInterval)#%d (%d) {
71  ["y"]=>
72  int(0)
73  ["m"]=>
74  int(0)
75  ["d"]=>
76  int(0)
77  ["h"]=>
78  int(4)
79  ["i"]=>
80  int(0)
81  ["s"]=>
82  int(0)
83  ["f"]=>
84  float(0)
85  ["invert"]=>
86  int(0)
87  ["days"]=>
88  int(0)
89  ["from_string"]=>
90  bool(false)
91}
92object(DatePeriod)#%d (%d) {
93  ["start"]=>
94  object(DateTime)#%d (%d) {
95    ["date"]=>
96    string(26) "2003-01-02 08:00:00.000000"
97    ["timezone_type"]=>
98    int(3)
99    ["timezone"]=>
100    string(3) "UTC"
101  }
102  ["current"]=>
103  NULL
104  ["end"]=>
105  NULL
106  ["interval"]=>
107  object(DateInterval)#%d (%d) {
108    ["y"]=>
109    int(0)
110    ["m"]=>
111    int(0)
112    ["d"]=>
113    int(0)
114    ["h"]=>
115    int(4)
116    ["i"]=>
117    int(0)
118    ["s"]=>
119    int(0)
120    ["f"]=>
121    float(0)
122    ["invert"]=>
123    int(0)
124    ["days"]=>
125    int(0)
126    ["from_string"]=>
127    bool(false)
128  }
129  ["recurrences"]=>
130  int(3)
131  ["include_start_date"]=>
132  bool(true)
133  ["include_end_date"]=>
134  bool(false)
135}
136object(DateInterval)#%d (%d) {
137  ["y"]=>
138  int(7)
139  ["m"]=>
140  int(6)
141  ["d"]=>
142  int(5)
143  ["h"]=>
144  int(4)
145  ["i"]=>
146  int(3)
147  ["s"]=>
148  int(2)
149  ["f"]=>
150  float(0.876543)
151  ["invert"]=>
152  int(1)
153  ["days"]=>
154  int(2400)
155  ["from_string"]=>
156  bool(false)
157}
158object(DatePeriod)#%d (%d) {
159  ["start"]=>
160  object(DateTime)#%d (%d) {
161    ["date"]=>
162    string(26) "2003-01-02 08:00:00.000000"
163    ["timezone_type"]=>
164    int(3)
165    ["timezone"]=>
166    string(3) "UTC"
167  }
168  ["current"]=>
169  NULL
170  ["end"]=>
171  NULL
172  ["interval"]=>
173  object(DateInterval)#%d (%d) {
174    ["y"]=>
175    int(0)
176    ["m"]=>
177    int(0)
178    ["d"]=>
179    int(0)
180    ["h"]=>
181    int(4)
182    ["i"]=>
183    int(0)
184    ["s"]=>
185    int(0)
186    ["f"]=>
187    float(0)
188    ["invert"]=>
189    int(0)
190    ["days"]=>
191    int(0)
192    ["from_string"]=>
193    bool(false)
194  }
195  ["recurrences"]=>
196  int(3)
197  ["include_start_date"]=>
198  bool(true)
199  ["include_end_date"]=>
200  bool(false)
201}
202