forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDateTimeImmutable_serialization.phpt
118 lines (101 loc) · 2.29 KB
/
DateTimeImmutable_serialization.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
--TEST--
Test DateTimeImmutable::__serialize and DateTimeImmutable::__unserialize
--FILE--
<?php
//Set the default time zone
date_default_timezone_set("Europe/London");
$d = new DateTimeImmutable("2022-04-14 11:27:42");
echo "Original object:\n";
var_dump($d);
echo "\n\nSerialised object:\n";
$s = serialize($d);
var_dump($s);
echo "\n\nUnserialised object:\n";
$e = unserialize($s);
var_dump($e);
echo "\n\nCalling __serialize manually:\n";
var_dump($d->__serialize());
echo "\n\nCalling __unserialize manually:\n";
$d = new DateTimeImmutable;
$d->__unserialize(
[
'date' => '2022-04-14 11:27:42.541106',
'timezone_type' => 3,
'timezone' => 'UTC',
]
);
var_dump($d);
echo "\n\nCalling __unserialize a few more times, with abbreviations:\n";
$d->__unserialize(
[
'date' => '2022-04-14 11:27:42.541106',
'timezone_type' => 2,
'timezone' => 'CEST',
]
);
var_dump($d);
$d->__unserialize(
[
'date' => '2022-04-14 11:27:42.541106',
'timezone_type' => 1,
'timezone' => '+0130',
]
);
var_dump($d);
?>
--EXPECTF--
Original object:
object(DateTimeImmutable)#%d (%d) {
["date"]=>
string(26) "2022-04-14 11:27:42.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/London"
}
Serialised object:
string(135) "O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"2022-04-14 11:27:42.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:13:"Europe/London";}"
Unserialised object:
object(DateTimeImmutable)#%d (%d) {
["date"]=>
string(26) "2022-04-14 11:27:42.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/London"
}
Calling __serialize manually:
array(3) {
["date"]=>
string(26) "2022-04-14 11:27:42.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/London"
}
Calling __unserialize manually:
object(DateTimeImmutable)#%d (%d) {
["date"]=>
string(26) "2022-04-14 11:27:42.541106"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
Calling __unserialize a few more times, with abbreviations:
object(DateTimeImmutable)#%d (%d) {
["date"]=>
string(26) "2022-04-14 11:27:42.541106"
["timezone_type"]=>
int(2)
["timezone"]=>
string(4) "CEST"
}
object(DateTimeImmutable)#%d (%d) {
["date"]=>
string(26) "2022-04-14 11:27:42.541106"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "+01:30"
}