From a09e2b4ac57fb0dd4226f7439e45d04236ee25ce Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 25 Apr 2022 09:39:59 -0700 Subject: [PATCH] [VarExporter] Fix exporting DateTime objects on PHP 8.2 --- .../VarExporter/Internal/Exporter.php | 7 +- .../VarExporter/Tests/Fixtures/datetime.php | 70 ++++++++++++++++--- 2 files changed, 63 insertions(+), 14 deletions(-) diff --git a/src/Symfony/Component/VarExporter/Internal/Exporter.php b/src/Symfony/Component/VarExporter/Internal/Exporter.php index 078359af55309..8e03755d87078 100644 --- a/src/Symfony/Component/VarExporter/Internal/Exporter.php +++ b/src/Symfony/Component/VarExporter/Internal/Exporter.php @@ -110,12 +110,7 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount $arrayValue = (array) $value; } elseif ($value instanceof \Serializable || $value instanceof \__PHP_Incomplete_Class - || $value instanceof \DatePeriod - || (\PHP_VERSION_ID >= 80200 && ( - $value instanceof \DateTimeInterface - || $value instanceof \DateTimeZone - || $value instanceof \DateInterval - )) + || PHP_VERSION_ID < 80200 && $value instanceof \DatePeriod ) { ++$objectsCount; $objectsPool[$value] = [$id = \count($objectsPool), serialize($value), [], 0]; diff --git a/src/Symfony/Component/VarExporter/Tests/Fixtures/datetime.php b/src/Symfony/Component/VarExporter/Tests/Fixtures/datetime.php index e9f41f9ade34c..6429f10efe9f1 100644 --- a/src/Symfony/Component/VarExporter/Tests/Fixtures/datetime.php +++ b/src/Symfony/Component/VarExporter/Tests/Fixtures/datetime.php @@ -1,13 +1,15 @@ '1970-01-01 00:00:00.000000', + 'timezone_type' => 1, + 'timezone' => '+00:00', + ], + -1 => [ + 'date' => '1970-01-01 00:00:00.000000', + 'timezone_type' => 1, + 'timezone' => '+00:00', + ], + -2 => [ + 'timezone_type' => 3, + 'timezone' => 'Europe/Paris', + ], + -3 => [ + 'y' => 0, + 'm' => 0, + 'd' => 7, + 'h' => 0, + 'i' => 0, + 's' => 0, + 'f' => 0.0, + 'invert' => 0, + 'days' => 7, + 'from_string' => false, + ], + -5 => [ + 'date' => '2009-10-11 00:00:00.000000', + 'timezone_type' => 3, + 'timezone' => 'Europe/Paris', + ], + -6 => [ + 'y' => 0, + 'm' => 0, + 'd' => 7, + 'h' => 0, + 'i' => 0, + 's' => 0, + 'f' => 0.0, + 'invert' => 0, + 'days' => 7, + 'from_string' => false, + ], + -4 => [ + 'start' => $o[5], + 'current' => null, + 'end' => null, + 'interval' => $o[6], + 'recurrences' => 5, + 'include_start_date' => true, + ], + ] );