xref: /PHP-7.0/ext/date/tests/bug53437.phpt (revision fdb2709d)
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==DONE==
26--EXPECT--
27Original:
282010-01-01 00:00:00
292010-01-02 00:00:00
302010-01-03 00:00:00
31
32object(DatePeriod)#1 (6) {
33  ["start"]=>
34  object(DateTime)#2 (3) {
35    ["date"]=>
36    string(26) "2010-01-01 00:00:00.000000"
37    ["timezone_type"]=>
38    int(3)
39    ["timezone"]=>
40    string(3) "UTC"
41  }
42  ["current"]=>
43  object(DateTime)#4 (3) {
44    ["date"]=>
45    string(26) "2010-01-04 00:00:00.000000"
46    ["timezone_type"]=>
47    int(3)
48    ["timezone"]=>
49    string(3) "UTC"
50  }
51  ["end"]=>
52  NULL
53  ["interval"]=>
54  object(DateInterval)#5 (15) {
55    ["y"]=>
56    int(0)
57    ["m"]=>
58    int(0)
59    ["d"]=>
60    int(1)
61    ["h"]=>
62    int(0)
63    ["i"]=>
64    int(0)
65    ["s"]=>
66    int(0)
67    ["weekday"]=>
68    int(0)
69    ["weekday_behavior"]=>
70    int(0)
71    ["first_last_day_of"]=>
72    int(0)
73    ["invert"]=>
74    int(0)
75    ["days"]=>
76    bool(false)
77    ["special_type"]=>
78    int(0)
79    ["special_amount"]=>
80    int(0)
81    ["have_weekday_relative"]=>
82    int(0)
83    ["have_special_relative"]=>
84    int(0)
85  }
86  ["recurrences"]=>
87  int(3)
88  ["include_start_date"]=>
89  bool(true)
90}
91object(DatePeriod)#5 (6) {
92  ["start"]=>
93  object(DateTime)#10 (3) {
94    ["date"]=>
95    string(26) "2010-01-01 00:00:00.000000"
96    ["timezone_type"]=>
97    int(3)
98    ["timezone"]=>
99    string(3) "UTC"
100  }
101  ["current"]=>
102  object(DateTime)#7 (3) {
103    ["date"]=>
104    string(26) "2010-01-04 00:00:00.000000"
105    ["timezone_type"]=>
106    int(3)
107    ["timezone"]=>
108    string(3) "UTC"
109  }
110  ["end"]=>
111  NULL
112  ["interval"]=>
113  object(DateInterval)#8 (15) {
114    ["y"]=>
115    int(0)
116    ["m"]=>
117    int(0)
118    ["d"]=>
119    int(1)
120    ["h"]=>
121    int(0)
122    ["i"]=>
123    int(0)
124    ["s"]=>
125    int(0)
126    ["weekday"]=>
127    int(0)
128    ["weekday_behavior"]=>
129    int(0)
130    ["first_last_day_of"]=>
131    int(0)
132    ["invert"]=>
133    int(0)
134    ["days"]=>
135    int(0)
136    ["special_type"]=>
137    int(0)
138    ["special_amount"]=>
139    int(0)
140    ["have_weekday_relative"]=>
141    int(0)
142    ["have_special_relative"]=>
143    int(0)
144  }
145  ["recurrences"]=>
146  int(3)
147  ["include_start_date"]=>
148  bool(true)
149}
150Unserialized:
1512010-01-01 00:00:00
1522010-01-02 00:00:00
1532010-01-03 00:00:00
154==DONE==
155