Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a09e2b4

Browse files
[VarExporter] Fix exporting DateTime objects on PHP 8.2
1 parent aca1d8f commit a09e2b4

File tree

2 files changed

+63
-14
lines changed

2 files changed

+63
-14
lines changed

src/Symfony/Component/VarExporter/Internal/Exporter.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,7 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
110110
$arrayValue = (array) $value;
111111
} elseif ($value instanceof \Serializable
112112
|| $value instanceof \__PHP_Incomplete_Class
113-
|| $value instanceof \DatePeriod
114-
|| (\PHP_VERSION_ID >= 80200 && (
115-
$value instanceof \DateTimeInterface
116-
|| $value instanceof \DateTimeZone
117-
|| $value instanceof \DateInterval
118-
))
113+
|| PHP_VERSION_ID < 80200 && $value instanceof \DatePeriod
119114
) {
120115
++$objectsCount;
121116
$objectsPool[$value] = [$id = \count($objectsPool), serialize($value), [], 0];
Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22

33
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
4-
$o = \Symfony\Component\VarExporter\Internal\Registry::unserialize([], [
5-
'O:8:"DateTime":3:{s:4:"date";s:26:"1970-01-01 00:00:00.000000";s:13:"timezone_type";i:1;s:8:"timezone";s:6:"+00:00";}',
6-
'O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"1970-01-01 00:00:00.000000";s:13:"timezone_type";i:1;s:8:"timezone";s:6:"+00:00";}',
7-
'O:12:"DateTimeZone":2:{s:13:"timezone_type";i:3;s:8:"timezone";s:12:"Europe/Paris";}',
8-
'O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:7;s:1:"h";i:0;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";i:7;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}',
9-
'O:10:"DatePeriod":6:{s:5:"start";O:8:"DateTime":3:{s:4:"date";s:26:"2009-10-11 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:12:"Europe/Paris";}s:7:"current";N;s:3:"end";N;s:8:"interval";O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:7;s:1:"h";i:0;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";i:7;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}s:11:"recurrences";i:5;s:18:"include_start_date";b:1;}',
10-
]),
4+
$o = [
5+
clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['DateTime'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('DateTime')),
6+
clone ($p['DateTimeImmutable'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('DateTimeImmutable')),
7+
clone ($p['DateTimeZone'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('DateTimeZone')),
8+
clone ($p['DateInterval'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('DateInterval')),
9+
clone ($p['DatePeriod'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('DatePeriod')),
10+
clone $p['DateTime'],
11+
clone $p['DateInterval'],
12+
],
1113
null,
1214
[],
1315
[
@@ -17,5 +19,57 @@
1719
$o[3],
1820
$o[4],
1921
],
20-
[]
22+
[
23+
[
24+
'date' => '1970-01-01 00:00:00.000000',
25+
'timezone_type' => 1,
26+
'timezone' => '+00:00',
27+
],
28+
-1 => [
29+
'date' => '1970-01-01 00:00:00.000000',
30+
'timezone_type' => 1,
31+
'timezone' => '+00:00',
32+
],
33+
-2 => [
34+
'timezone_type' => 3,
35+
'timezone' => 'Europe/Paris',
36+
],
37+
-3 => [
38+
'y' => 0,
39+
'm' => 0,
40+
'd' => 7,
41+
'h' => 0,
42+
'i' => 0,
43+
's' => 0,
44+
'f' => 0.0,
45+
'invert' => 0,
46+
'days' => 7,
47+
'from_string' => false,
48+
],
49+
-5 => [
50+
'date' => '2009-10-11 00:00:00.000000',
51+
'timezone_type' => 3,
52+
'timezone' => 'Europe/Paris',
53+
],
54+
-6 => [
55+
'y' => 0,
56+
'm' => 0,
57+
'd' => 7,
58+
'h' => 0,
59+
'i' => 0,
60+
's' => 0,
61+
'f' => 0.0,
62+
'invert' => 0,
63+
'days' => 7,
64+
'from_string' => false,
65+
],
66+
-4 => [
67+
'start' => $o[5],
68+
'current' => null,
69+
'end' => null,
70+
'interval' => $o[6],
71+
'recurrences' => 5,
72+
'include_start_date' => true,
73+
],
74+
]
2175
);

0 commit comments

Comments
 (0)