xref: /PHP-8.4/ext/date/tests/gh10747-4.phpt (revision f575027b)
1--TEST--
2Bug GH-10747 (Private fields in serialized DatePeriod objects throw)
3--INI--
4date.timezone=UTC
5--FILE--
6<?php
7class I extends DatePeriod
8{
9	private   int $var1;
10	private       $var2 = 2;
11	protected int $var3 = 3;
12	protected     $var4;
13
14	function __construct($start, $interval, $end)
15	{
16		parent::__construct($start, $interval, $end);
17		$this->var1 = 1;
18		$this->var4 = 4;
19	}
20}
21
22$i = new I(new DateTimeImmutable('2023-03-03 16:24'), DateInterval::createFromDateString('+1 hour'), new DateTimeImmutable('2023-03-09 16:24'));
23$s = serialize($i);
24$u = unserialize($s);
25
26var_dump($i, str_replace(chr(0), '!', $s), $u);
27?>
28--EXPECTF--
29object(I)#1 (11) {
30  ["start"]=>
31  object(DateTimeImmutable)#5 (3) {
32    ["date"]=>
33    string(26) "2023-03-03 16:24:00.000000"
34    ["timezone_type"]=>
35    int(3)
36    ["timezone"]=>
37    string(3) "UTC"
38  }
39  ["current"]=>
40  NULL
41  ["end"]=>
42  object(DateTimeImmutable)#6 (3) {
43    ["date"]=>
44    string(26) "2023-03-09 16:24:00.000000"
45    ["timezone_type"]=>
46    int(3)
47    ["timezone"]=>
48    string(3) "UTC"
49  }
50  ["interval"]=>
51  object(DateInterval)#7 (10) {
52    ["y"]=>
53    int(0)
54    ["m"]=>
55    int(0)
56    ["d"]=>
57    int(0)
58    ["h"]=>
59    int(1)
60    ["i"]=>
61    int(0)
62    ["s"]=>
63    int(0)
64    ["f"]=>
65    float(0)
66    ["invert"]=>
67    int(0)
68    ["days"]=>
69    bool(false)
70    ["from_string"]=>
71    bool(false)
72  }
73  ["recurrences"]=>
74  int(1)
75  ["include_start_date"]=>
76  bool(true)
77  ["include_end_date"]=>
78  bool(false)
79  ["var1":"I":private]=>
80  int(1)
81  ["var2":"I":private]=>
82  int(2)
83  ["var3":protected]=>
84  int(3)
85  ["var4":protected]=>
86  int(4)
87}
88string(631) "O:1:"I":11:{s:5:"start";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"2023-03-03 16:24:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";}s:7:"current";N;s:3:"end";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"2023-03-09 16:24:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";}s:8:"interval";O:12:"DateInterval":10:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h";i:1;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:1;s:18:"include_start_date";b:1;s:16:"include_end_date";b:0;s:7:"!I!var1";i:1;s:7:"!I!var2";i:2;s:7:"!*!var3";i:3;s:7:"!*!var4";i:4;}"
89object(I)#2 (11) {
90  ["start"]=>
91  object(DateTimeImmutable)#9 (3) {
92    ["date"]=>
93    string(26) "2023-03-03 16:24:00.000000"
94    ["timezone_type"]=>
95    int(3)
96    ["timezone"]=>
97    string(3) "UTC"
98  }
99  ["current"]=>
100  NULL
101  ["end"]=>
102  object(DateTimeImmutable)#10 (3) {
103    ["date"]=>
104    string(26) "2023-03-09 16:24:00.000000"
105    ["timezone_type"]=>
106    int(3)
107    ["timezone"]=>
108    string(3) "UTC"
109  }
110  ["interval"]=>
111  object(DateInterval)#11 (10) {
112    ["y"]=>
113    int(0)
114    ["m"]=>
115    int(0)
116    ["d"]=>
117    int(0)
118    ["h"]=>
119    int(1)
120    ["i"]=>
121    int(0)
122    ["s"]=>
123    int(0)
124    ["f"]=>
125    float(0)
126    ["invert"]=>
127    int(0)
128    ["days"]=>
129    bool(false)
130    ["from_string"]=>
131    bool(false)
132  }
133  ["recurrences"]=>
134  int(1)
135  ["include_start_date"]=>
136  bool(true)
137  ["include_end_date"]=>
138  bool(false)
139  ["var1":"I":private]=>
140  int(1)
141  ["var2":"I":private]=>
142  int(2)
143  ["var3":protected]=>
144  int(3)
145  ["var4":protected]=>
146  int(4)
147}
148