123
diff --git a/src/Symfony/Component/VarDumper/Tests/Dumper/HtmlDumperTest.php b/src/Symfony/Component/VarDumper/Tests/Dumper/HtmlDumperTest.php
index e5ad368330f1c..9921dc715a4dd 100644
--- a/src/Symfony/Component/VarDumper/Tests/Dumper/HtmlDumperTest.php
+++ b/src/Symfony/Component/VarDumper/Tests/Dumper/HtmlDumperTest.php
@@ -66,7 +66,7 @@ public function testGet()
6 => {$intMax}
"str" => "d&%s;j&%s;\\n"
7 => b"""
- é\\x00test\\t\\n
+ é\\x00test\\t\\n
ing
"""
"[]" => []
diff --git a/src/Symfony/Component/VarDumper/Tests/Fixtures/dumb-var.php b/src/Symfony/Component/VarDumper/Tests/Fixtures/dumb-var.php
index 67e53badb6445..4ea8c8ba6ec08 100644
--- a/src/Symfony/Component/VarDumper/Tests/Fixtures/dumb-var.php
+++ b/src/Symfony/Component/VarDumper/Tests/Fixtures/dumb-var.php
@@ -3,6 +3,7 @@
namespace Symfony\Component\VarDumper\Tests\Fixture;
if (!class_exists(\Symfony\Component\VarDumper\Tests\Fixture\DumbFoo::class)) {
+ #[\AllowDynamicProperties]
class DumbFoo
{
public $foo = 'foo';
diff --git a/src/Symfony/Component/VarExporter/Internal/Exporter.php b/src/Symfony/Component/VarExporter/Internal/Exporter.php
index 4c49d87da61bf..c46eb50aa988d 100644
--- a/src/Symfony/Component/VarExporter/Internal/Exporter.php
+++ b/src/Symfony/Component/VarExporter/Internal/Exporter.php
@@ -108,7 +108,15 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
}
$properties = ['SplObjectStorage' => ["\0" => $properties]];
$arrayValue = (array) $value;
- } elseif ($value instanceof \Serializable || $value instanceof \__PHP_Incomplete_Class) {
+ } 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
+ ))
+ ) {
++$objectsCount;
$objectsPool[$value] = [$id = \count($objectsPool), serialize($value), [], 0];
$value = new Reference($id);
diff --git a/src/Symfony/Component/VarExporter/Internal/Hydrator.php b/src/Symfony/Component/VarExporter/Internal/Hydrator.php
index 364d292d916e7..5ed6bdc948e63 100644
--- a/src/Symfony/Component/VarExporter/Internal/Hydrator.php
+++ b/src/Symfony/Component/VarExporter/Internal/Hydrator.php
@@ -55,45 +55,14 @@ public static function hydrate($objects, $values, $properties, $value, $wakeups)
public static function getHydrator($class)
{
- if ('stdClass' === $class) {
- return self::$hydrators[$class] = static function ($properties, $objects) {
- foreach ($properties as $name => $values) {
- foreach ($values as $i => $v) {
- $objects[$i]->$name = $v;
- }
- }
- };
- }
-
- if (!class_exists($class) && !interface_exists($class, false) && !trait_exists($class, false)) {
- throw new ClassNotFoundException($class);
- }
- $classReflector = new \ReflectionClass($class);
-
- if (!$classReflector->isInternal()) {
- return self::$hydrators[$class] = (self::$hydrators['stdClass'] ?? self::getHydrator('stdClass'))->bindTo(null, $class);
- }
-
- if ($classReflector->name !== $class) {
- return self::$hydrators[$classReflector->name] ?? self::getHydrator($classReflector->name);
- }
-
switch ($class) {
- case 'ArrayIterator':
- case 'ArrayObject':
- $constructor = \Closure::fromCallable([$classReflector->getConstructor(), 'invokeArgs']);
-
- return self::$hydrators[$class] = static function ($properties, $objects) use ($constructor) {
+ case 'stdClass':
+ return self::$hydrators[$class] = static function ($properties, $objects) {
foreach ($properties as $name => $values) {
- if ("\0" !== $name) {
- foreach ($values as $i => $v) {
- $objects[$i]->$name = $v;
- }
+ foreach ($values as $i => $v) {
+ $objects[$i]->$name = $v;
}
}
- foreach ($properties["\0"] ?? [] as $i => $v) {
- $constructor($objects[$i], $v);
- }
};
case 'ErrorException':
@@ -122,6 +91,38 @@ public static function getHydrator($class)
};
}
+ if (!class_exists($class) && !interface_exists($class, false) && !trait_exists($class, false)) {
+ throw new ClassNotFoundException($class);
+ }
+ $classReflector = new \ReflectionClass($class);
+
+ switch ($class) {
+ case 'ArrayIterator':
+ case 'ArrayObject':
+ $constructor = \Closure::fromCallable([$classReflector->getConstructor(), 'invokeArgs']);
+
+ return self::$hydrators[$class] = static function ($properties, $objects) use ($constructor) {
+ foreach ($properties as $name => $values) {
+ if ("\0" !== $name) {
+ foreach ($values as $i => $v) {
+ $objects[$i]->$name = $v;
+ }
+ }
+ }
+ foreach ($properties["\0"] ?? [] as $i => $v) {
+ $constructor($objects[$i], $v);
+ }
+ };
+ }
+
+ if (!$classReflector->isInternal()) {
+ return self::$hydrators[$class] = (self::$hydrators['stdClass'] ?? self::getHydrator('stdClass'))->bindTo(null, $class);
+ }
+
+ if ($classReflector->name !== $class) {
+ return self::$hydrators[$classReflector->name] ?? self::getHydrator($classReflector->name);
+ }
+
$propertySetters = [];
foreach ($classReflector->getProperties() as $propertyReflector) {
if (!$propertyReflector->isStatic()) {
diff --git a/src/Symfony/Component/VarExporter/Tests/Fixtures/array-object.php b/src/Symfony/Component/VarExporter/Tests/Fixtures/array-object.php
index 4e2d4d13a3d89..22fb5c9b247d9 100644
--- a/src/Symfony/Component/VarExporter/Tests/Fixtures/array-object.php
+++ b/src/Symfony/Component/VarExporter/Tests/Fixtures/array-object.php
@@ -2,8 +2,8 @@
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
- clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['ArrayObject'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('ArrayObject')),
- clone $p['ArrayObject'],
+ clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['Symfony\\Component\\VarExporter\\Tests\\ArrayObject'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\ArrayObject')),
+ clone ($p['ArrayObject'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('ArrayObject')),
],
null,
[],
diff --git a/src/Symfony/Component/VarExporter/Tests/Fixtures/datetime-legacy.php b/src/Symfony/Component/VarExporter/Tests/Fixtures/datetime-legacy.php
new file mode 100644
index 0000000000000..7b217c5fb21b0
--- /dev/null
+++ b/src/Symfony/Component/VarExporter/Tests/Fixtures/datetime-legacy.php
@@ -0,0 +1,92 @@
+ 'O:10:"DatePeriod":6:{s:5:"start";O:8:"DateTime":3:{s:4:"date";s:26:"2012-07-01 00:00:00.000000";s:13:"timezone_type";i:1;s:8:"timezone";s:6:"+00:00";}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";b:0;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;}',
+ ]),
+ null,
+ [
+ 'stdClass' => [
+ 'date' => [
+ '1970-01-01 00:00:00.000000',
+ '1970-01-01 00:00:00.000000',
+ ],
+ 'timezone_type' => [
+ 1,
+ 1,
+ 3,
+ ],
+ 'timezone' => [
+ '+00:00',
+ '+00:00',
+ 'Europe/Paris',
+ ],
+ 'y' => [
+ 3 => 0,
+ ],
+ 'm' => [
+ 3 => 0,
+ ],
+ 'd' => [
+ 3 => 7,
+ ],
+ 'h' => [
+ 3 => 0,
+ ],
+ 'i' => [
+ 3 => 0,
+ ],
+ 's' => [
+ 3 => 0,
+ ],
+ 'f' => [
+ 3 => 0.0,
+ ],
+ 'weekday' => [
+ 3 => 0,
+ ],
+ 'weekday_behavior' => [
+ 3 => 0,
+ ],
+ 'first_last_day_of' => [
+ 3 => 0,
+ ],
+ 'invert' => [
+ 3 => 0,
+ ],
+ 'days' => [
+ 3 => false,
+ ],
+ 'special_type' => [
+ 3 => 0,
+ ],
+ 'special_amount' => [
+ 3 => 0,
+ ],
+ 'have_weekday_relative' => [
+ 3 => 0,
+ ],
+ 'have_special_relative' => [
+ 3 => 0,
+ ],
+ ],
+ ],
+ [
+ $o[0],
+ $o[1],
+ $o[2],
+ $o[3],
+ $o[4],
+ ],
+ [
+ 1 => 0,
+ 1,
+ 2,
+ 3,
+ ]
+);
diff --git a/src/Symfony/Component/VarExporter/Tests/Fixtures/datetime.php b/src/Symfony/Component/VarExporter/Tests/Fixtures/datetime.php
index 1c916458c4f1a..1de8fa03f0919 100644
--- a/src/Symfony/Component/VarExporter/Tests/Fixtures/datetime.php
+++ b/src/Symfony/Component/VarExporter/Tests/Fixtures/datetime.php
@@ -1,25 +1,21 @@
[
- 'date' => [
- '1970-01-01 00:00:00.000000',
- ],
- 'timezone_type' => [
- 1,
- ],
- 'timezone' => [
- '+00:00',
- ],
- ],
+ $o[0],
+ $o[1],
+ $o[2],
+ $o[3],
+ $o[4],
],
- $o[0],
- [
- 1 => 0,
- ]
+ []
);
diff --git a/src/Symfony/Component/VarExporter/Tests/InstantiatorTest.php b/src/Symfony/Component/VarExporter/Tests/InstantiatorTest.php
index 744e576c0a0c9..cbd223642320b 100644
--- a/src/Symfony/Component/VarExporter/Tests/InstantiatorTest.php
+++ b/src/Symfony/Component/VarExporter/Tests/InstantiatorTest.php
@@ -53,16 +53,16 @@ public function testInstantiate()
$expected = [
"\0".__NAMESPACE__."\Bar\0priv" => 123,
"\0".__NAMESPACE__."\Foo\0priv" => 234,
+ 'dyn' => 345,
];
- $actual = (array) Instantiator::instantiate(Bar::class, ['priv' => 123], [Foo::class => ['priv' => 234]]);
+ $actual = (array) Instantiator::instantiate(Bar::class, ['dyn' => 345, 'priv' => 123], [Foo::class => ['priv' => 234]]);
ksort($actual);
$this->assertSame($expected, $actual);
- $e = Instantiator::instantiate('Exception', ['foo' => 123, 'trace' => [234]]);
+ $e = Instantiator::instantiate('Exception', ['trace' => [234]]);
- $this->assertSame(123, $e->foo);
$this->assertSame([234], $e->getTrace());
}
}
@@ -72,6 +72,7 @@ class Foo
private $priv;
}
+#[\AllowDynamicProperties]
class Bar extends Foo
{
private $priv;
diff --git a/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php b/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php
index fffccd4b53db1..f87e4e9b01d1e 100644
--- a/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php
+++ b/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php
@@ -95,7 +95,9 @@ public function testExport(string $testName, $value, bool $staticValueExpected =
$dump = "= 70406 || !\in_array($testName, ['array-object', 'array-iterator', 'array-object-custom', 'spl-object-storage', 'final-array-iterator', 'final-error'], true)) {
+ if (\PHP_VERSION_ID < 80200 && 'datetime' === $testName) {
+ $fixtureFile = __DIR__.'/Fixtures/'.$testName.'-legacy.php';
+ } elseif (\PHP_VERSION_ID >= 70406 || !\in_array($testName, ['array-object', 'array-iterator', 'array-object-custom', 'spl-object-storage', 'final-array-iterator', 'final-error'], true)) {
$fixtureFile = __DIR__.'/Fixtures/'.$testName.'.php';
} elseif (\PHP_VERSION_ID < 70400) {
$fixtureFile = __DIR__.'/Fixtures/'.$testName.'-legacy.php';
@@ -127,9 +129,15 @@ public function provideExport()
yield ['bool', true, true];
yield ['simple-array', [123, ['abc']], true];
yield ['partially-indexed-array', [5 => true, 1 => true, 2 => true, 6 => true], true];
- yield ['datetime', \DateTime::createFromFormat('U', 0)];
-
- $value = new \ArrayObject();
+ yield ['datetime', [
+ \DateTime::createFromFormat('U', 0),
+ \DateTimeImmutable::createFromFormat('U', 0),
+ new \DateTimeZone('Europe/Paris'),
+ new \DateInterval('P7D'),
+ new \DatePeriod('R4/2012-07-01T00:00:00Z/P7D'),
+ ]];
+
+ $value = \PHP_VERSION_ID >= 70406 ? new ArrayObject() : new \ArrayObject();
$value[0] = 1;
$value->foo = new \ArrayObject();
$value[1] = $value;
@@ -436,3 +444,8 @@ public function unserialize($ser)
throw new \BadMethodCallException();
}
}
+
+#[\AllowDynamicProperties]
+class ArrayObject extends \ArrayObject
+{
+}
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy