1--TEST--
2Test DatePeriod::__serialize and DatePeriod::__unserialize (ISO String)
3--FILE--
4<?php
5date_default_timezone_set("Europe/London");
6
7$d = DatePeriod::createFromISO8601String('R4/2012-07-01T00:00:00Z/P7D');
8echo "Original object:\n";
9var_dump($d);
10
11echo "\n\nSerialised object:\n";
12$s = serialize($d);
13var_dump($s);
14
15echo "\n\nUnserialised object:\n";
16$e = unserialize($s);
17var_dump($e);
18
19echo "\n\nCalling __serialize manually:\n";
20var_dump($d->__serialize());
21
22?>
23--EXPECTF--
24Original object:
25object(DatePeriod)#%d (%d) {
26  ["start"]=>
27  object(DateTimeImmutable)#%d (%d) {
28    ["date"]=>
29    string(26) "2012-07-01 00:00:00.000000"
30    ["timezone_type"]=>
31    int(1)
32    ["timezone"]=>
33    string(6) "+00:00"
34  }
35  ["current"]=>
36  NULL
37  ["end"]=>
38  NULL
39  ["interval"]=>
40  object(DateInterval)#%d (%d) {
41    ["y"]=>
42    int(0)
43    ["m"]=>
44    int(0)
45    ["d"]=>
46    int(7)
47    ["h"]=>
48    int(0)
49    ["i"]=>
50    int(0)
51    ["s"]=>
52    int(0)
53    ["f"]=>
54    float(0)
55    ["invert"]=>
56    int(0)
57    ["days"]=>
58    bool(false)
59    ["from_string"]=>
60    bool(false)
61  }
62  ["recurrences"]=>
63  int(5)
64  ["include_start_date"]=>
65  bool(true)
66  ["include_end_date"]=>
67  bool(false)
68}
69
70
71Serialised object:
72string(%d) "O:10:"DatePeriod":7:{s:5:"start";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"2012-07-01 00:00:00.000000";s:13:"timezone_type";i:1;s:8:"timezone";s:6:"+00:00";}s:7:"current";N;s:3:"end";N;s:8:"interval";O:12:"DateInterval":10:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:7;s:1:"h";i:0;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";b:0;s:11:"from_string";b:0;}s:11:"recurrences";i:5;s:18:"include_start_date";b:1;s:16:"include_end_date";b:0;}"
73
74
75Unserialised object:
76object(DatePeriod)#%d (%d) {
77  ["start"]=>
78  object(DateTimeImmutable)#%d (%d) {
79    ["date"]=>
80    string(26) "2012-07-01 00:00:00.000000"
81    ["timezone_type"]=>
82    int(1)
83    ["timezone"]=>
84    string(6) "+00:00"
85  }
86  ["current"]=>
87  NULL
88  ["end"]=>
89  NULL
90  ["interval"]=>
91  object(DateInterval)#%d (%d) {
92    ["y"]=>
93    int(0)
94    ["m"]=>
95    int(0)
96    ["d"]=>
97    int(7)
98    ["h"]=>
99    int(0)
100    ["i"]=>
101    int(0)
102    ["s"]=>
103    int(0)
104    ["f"]=>
105    float(0)
106    ["invert"]=>
107    int(0)
108    ["days"]=>
109    bool(false)
110    ["from_string"]=>
111    bool(false)
112  }
113  ["recurrences"]=>
114  int(5)
115  ["include_start_date"]=>
116  bool(true)
117  ["include_end_date"]=>
118  bool(false)
119}
120
121
122Calling __serialize manually:
123array(%d) {
124  ["start"]=>
125  object(DateTimeImmutable)#%d (%d) {
126    ["date"]=>
127    string(26) "2012-07-01 00:00:00.000000"
128    ["timezone_type"]=>
129    int(1)
130    ["timezone"]=>
131    string(6) "+00:00"
132  }
133  ["current"]=>
134  NULL
135  ["end"]=>
136  NULL
137  ["interval"]=>
138  object(DateInterval)#%d (%d) {
139    ["y"]=>
140    int(0)
141    ["m"]=>
142    int(0)
143    ["d"]=>
144    int(7)
145    ["h"]=>
146    int(0)
147    ["i"]=>
148    int(0)
149    ["s"]=>
150    int(0)
151    ["f"]=>
152    float(0)
153    ["invert"]=>
154    int(0)
155    ["days"]=>
156    bool(false)
157    ["from_string"]=>
158    bool(false)
159  }
160  ["recurrences"]=>
161  int(5)
162  ["include_start_date"]=>
163  bool(true)
164  ["include_end_date"]=>
165  bool(false)
166}
167