Skip to content

Commit d76a885

Browse files
committed
Serialization fixes
1 parent 3e130bc commit d76a885

File tree

3 files changed

+35
-27
lines changed

3 files changed

+35
-27
lines changed

ext/date/php_date.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5912,13 +5912,14 @@ PHP_METHOD(DatePeriod, __wakeup)
59125912
ZEND_PARSE_PARAMETERS_NONE();
59135913

59145914
period_obj = Z_PHPPERIOD_P(object);
5915-
59165915
myht = Z_OBJPROP_P(object);
59175916

59185917
if (!php_date_period_initialize_from_hash(period_obj, myht)) {
59195918
zend_throw_error(NULL, "Invalid serialization data for DatePeriod object");
59205919
RETURN_THROWS();
59215920
}
5921+
5922+
restore_custom_dateperiod_properties(object, myht);
59225923
}
59235924
/* }}} */
59245925

ext/date/tests/date_period_unserialize3.phpt

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ $period = new DatePeriod($start, $interval, $end);
1111
try {
1212
$period->__unserialize(
1313
[
14-
"current" => new DateTime,
15-
"start" => new DateTime,
16-
"end" => new DateTime,
14+
"current" => new DateTime("2024-08-27 00:00:00"),
15+
"start" => new DateTime("2024-08-28 00:00:00"),
16+
"end" => new DateTime("2024-08-29 00:00:00"),
1717
"interval" => new DateInterval('P2D'),
1818
"recurrences" => 2,
1919
"include_start_date" => "wrong type",
@@ -33,18 +33,25 @@ object(DatePeriod)#%d (%d) {
3333
["start"]=>
3434
object(DateTime)#%d (%d) {
3535
["date"]=>
36-
string(26) "2022-07-14 00:00:00.000000"
36+
string(26) "2024-08-28 00:00:00.000000"
3737
["timezone_type"]=>
3838
int(3)
3939
["timezone"]=>
4040
string(3) "UTC"
4141
}
4242
["current"]=>
43-
NULL
43+
object(DateTime)#%d (%d) {
44+
["date"]=>
45+
string(26) "2024-08-27 00:00:00.000000"
46+
["timezone_type"]=>
47+
int(3)
48+
["timezone"]=>
49+
string(3) "UTC"
50+
}
4451
["end"]=>
4552
object(DateTime)#%d (%d) {
4653
["date"]=>
47-
string(26) "2022-07-16 00:00:00.000000"
54+
string(26) "2024-08-29 00:00:00.000000"
4855
["timezone_type"]=>
4956
int(3)
5057
["timezone"]=>
@@ -57,7 +64,7 @@ object(DatePeriod)#%d (%d) {
5764
["m"]=>
5865
int(0)
5966
["d"]=>
60-
int(1)
67+
int(2)
6168
["h"]=>
6269
int(0)
6370
["i"]=>
@@ -74,7 +81,7 @@ object(DatePeriod)#%d (%d) {
7481
bool(false)
7582
}
7683
["recurrences"]=>
77-
int(1)
84+
int(2)
7885
["include_start_date"]=>
7986
bool(true)
8087
["include_end_date"]=>

ext/date/tests/gh10747-4.phpt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,17 @@ $u = unserialize($s);
2626
var_dump($i, str_replace(chr(0), '!', $s), $u);
2727
?>
2828
--EXPECTF--
29-
object(I)#1 (11) {
29+
object(I)#%d (%d) {
30+
["var1":"I":private]=>
31+
int(1)
32+
["var2":"I":private]=>
33+
int(2)
34+
["var3":protected]=>
35+
int(3)
36+
["var4":protected]=>
37+
int(4)
3038
["start"]=>
31-
object(DateTimeImmutable)#5 (3) {
39+
object(DateTimeImmutable)#%d (%d) {
3240
["date"]=>
3341
string(26) "2023-03-03 16:24:00.000000"
3442
["timezone_type"]=>
@@ -39,7 +47,7 @@ object(I)#1 (11) {
3947
["current"]=>
4048
NULL
4149
["end"]=>
42-
object(DateTimeImmutable)#6 (3) {
50+
object(DateTimeImmutable)#%d (%d) {
4351
["date"]=>
4452
string(26) "2023-03-09 16:24:00.000000"
4553
["timezone_type"]=>
@@ -48,7 +56,7 @@ object(I)#1 (11) {
4856
string(3) "UTC"
4957
}
5058
["interval"]=>
51-
object(DateInterval)#7 (10) {
59+
object(DateInterval)#%d (%d) {
5260
["y"]=>
5361
int(0)
5462
["m"]=>
@@ -76,6 +84,9 @@ object(I)#1 (11) {
7684
bool(true)
7785
["include_end_date"]=>
7886
bool(false)
87+
}
88+
string(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;}"
89+
object(I)#%d (%d) {
7990
["var1":"I":private]=>
8091
int(1)
8192
["var2":"I":private]=>
@@ -84,11 +95,8 @@ object(I)#1 (11) {
8495
int(3)
8596
["var4":protected]=>
8697
int(4)
87-
}
88-
string(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;}"
89-
object(I)#2 (11) {
9098
["start"]=>
91-
object(DateTimeImmutable)#9 (3) {
99+
object(DateTimeImmutable)#%d (%d) {
92100
["date"]=>
93101
string(26) "2023-03-03 16:24:00.000000"
94102
["timezone_type"]=>
@@ -99,7 +107,7 @@ object(I)#2 (11) {
99107
["current"]=>
100108
NULL
101109
["end"]=>
102-
object(DateTimeImmutable)#10 (3) {
110+
object(DateTimeImmutable)#%d (%d) {
103111
["date"]=>
104112
string(26) "2023-03-09 16:24:00.000000"
105113
["timezone_type"]=>
@@ -108,7 +116,7 @@ object(I)#2 (11) {
108116
string(3) "UTC"
109117
}
110118
["interval"]=>
111-
object(DateInterval)#11 (10) {
119+
object(DateInterval)#%d (%d) {
112120
["y"]=>
113121
int(0)
114122
["m"]=>
@@ -136,12 +144,4 @@ object(I)#2 (11) {
136144
bool(true)
137145
["include_end_date"]=>
138146
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)
147147
}

0 commit comments

Comments
 (0)