xref: /PHP-8.2/ext/date/tests/bug53437_var0.phpt (revision 4f1b8f48)
1--TEST--
2Bug #53437 (Crash when using unserialized DatePeriod instance), variation 0
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 (%d) {
32  ["start"]=>
33  object(DateTime)#%d (%d) {
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 (%d) {
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 (%d) {
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    ["invert"]=>
69    int(0)
70    ["days"]=>
71    bool(false)
72    ["from_string"]=>
73    bool(false)
74  }
75  ["recurrences"]=>
76  int(3)
77  ["include_start_date"]=>
78  bool(true)
79  ["include_end_date"]=>
80  bool(false)
81}
82object(DatePeriod)#%d (%d) {
83  ["start"]=>
84  object(DateTime)#%d (%d) {
85    ["date"]=>
86    string(26) "2010-01-01 00:00:00.000000"
87    ["timezone_type"]=>
88    int(3)
89    ["timezone"]=>
90    string(3) "UTC"
91  }
92  ["current"]=>
93  object(DateTime)#%d (%d) {
94    ["date"]=>
95    string(26) "2010-01-04 00:00:00.000000"
96    ["timezone_type"]=>
97    int(3)
98    ["timezone"]=>
99    string(3) "UTC"
100  }
101  ["end"]=>
102  NULL
103  ["interval"]=>
104  object(DateInterval)#%d (%d) {
105    ["y"]=>
106    int(0)
107    ["m"]=>
108    int(0)
109    ["d"]=>
110    int(1)
111    ["h"]=>
112    int(0)
113    ["i"]=>
114    int(0)
115    ["s"]=>
116    int(0)
117    ["f"]=>
118    float(0)
119    ["invert"]=>
120    int(0)
121    ["days"]=>
122    bool(false)
123    ["from_string"]=>
124    bool(false)
125  }
126  ["recurrences"]=>
127  int(3)
128  ["include_start_date"]=>
129  bool(true)
130  ["include_end_date"]=>
131  bool(false)
132}
133Unserialized:
1342010-01-01 00:00:00
1352010-01-02 00:00:00
1362010-01-03 00:00:00
137