Skip to content

Commit 1a036dc

Browse files
[VarExporter] fix support for PHP 7.4
1 parent dd153d8 commit 1a036dc

15 files changed

+201
-64
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
155155
}
156156
$sleep[$n] = false;
157157
}
158-
if (!\array_key_exists($name, $proto) || $proto[$name] !== $v) {
158+
if (!\array_key_exists($name, $proto) || $proto[$name] !== $v || "\x00Error\x00trace" === $name || "\x00Exception\x00trace" === $name) {
159159
$properties[$c][$n] = $v;
160160
}
161161
}
@@ -291,7 +291,7 @@ private static function exportRegistry(Registry $value, string $indent, string $
291291
continue;
292292
}
293293
if (!Registry::$instantiableWithoutConstructor[$class]) {
294-
if (is_subclass_of($class, 'Serializable')) {
294+
if (is_subclass_of($class, 'Serializable') && !method_exists($class, '__unserialize')) {
295295
$serializables[$k] = 'C:'.\strlen($class).':"'.$class.'":0:{}';
296296
} else {
297297
$serializables[$k] = 'O:'.\strlen($class).':"'.$class.'":0:{}';

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static function getClassReflector($class, $instantiableWithoutConstructor
7575
} elseif (!$isClass || $reflector->isAbstract()) {
7676
throw new NotInstantiableTypeException($class);
7777
} elseif ($reflector->name !== $class) {
78-
$reflector = self::$reflectors[$name = $reflector->name] ?? self::getClassReflector($name, $instantiableWithoutConstructor, $cloneable);
78+
$reflector = self::$reflectors[$name = $reflector->name] ?? self::getClassReflector($name, false, $cloneable);
7979
self::$cloneable[$class] = self::$cloneable[$name];
8080
self::$instantiableWithoutConstructor[$class] = self::$instantiableWithoutConstructor[$name];
8181
self::$prototypes[$class] = self::$prototypes[$name];
@@ -86,7 +86,7 @@ public static function getClassReflector($class, $instantiableWithoutConstructor
8686
$proto = $reflector->newInstanceWithoutConstructor();
8787
$instantiableWithoutConstructor = true;
8888
} catch (\ReflectionException $e) {
89-
$proto = $reflector->implementsInterface('Serializable') && (\PHP_VERSION_ID < 70400 || !method_exists($class, '__unserialize')) ? 'C:' : 'O:';
89+
$proto = $reflector->implementsInterface('Serializable') && !method_exists($class, '__unserialize') ? 'C:' : 'O:';
9090
if ('C:' === $proto && !$reflector->getMethod('unserialize')->isInternal()) {
9191
$proto = null;
9292
} elseif (false === $proto = @unserialize($proto.\strlen($class).':"'.$class.'":0:{}')) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
4+
$o = [
5+
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['ArrayIterator'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('ArrayIterator')),
6+
],
7+
null,
8+
[
9+
'ArrayIterator' => [
10+
"\0" => [
11+
[
12+
[
13+
123,
14+
],
15+
1,
16+
],
17+
],
18+
],
19+
],
20+
$o[0],
21+
[]
22+
);

src/Symfony/Component/VarExporter/Tests/Fixtures/array-iterator.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@
55
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['ArrayIterator'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('ArrayIterator')),
66
],
77
null,
8+
[],
9+
$o[0],
810
[
9-
'ArrayIterator' => [
10-
"\0" => [
11-
[
12-
[
13-
123,
14-
],
15-
1,
16-
],
11+
[
12+
1,
13+
[
14+
123,
1715
],
16+
[],
1817
],
19-
],
20-
$o[0],
21-
[]
18+
]
2219
);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
4+
$o = [
5+
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['Symfony\\Component\\VarExporter\\Tests\\MyArrayObject'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\MyArrayObject')),
6+
],
7+
null,
8+
[
9+
'ArrayObject' => [
10+
"\0" => [
11+
[
12+
[
13+
234,
14+
],
15+
1,
16+
],
17+
],
18+
],
19+
],
20+
$o[0],
21+
[]
22+
);

src/Symfony/Component/VarExporter/Tests/Fixtures/array-object-custom.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['Symfony\\Component\\VarExporter\\Tests\\MyArrayObject'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\MyArrayObject')),
66
],
77
null,
8+
[],
9+
$o[0],
810
[
9-
'ArrayObject' => [
10-
"\0" => [
11-
[
12-
[
13-
234,
14-
],
15-
1,
16-
],
11+
[
12+
1,
13+
[
14+
234,
15+
],
16+
[
17+
"\0".'Symfony\\Component\\VarExporter\\Tests\\MyArrayObject'."\0".'unused' => 123,
1718
],
1819
],
19-
],
20-
$o[0],
21-
[]
20+
]
2221
);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
4+
$o = [
5+
clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['ArrayObject'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('ArrayObject')),
6+
clone $p['ArrayObject'],
7+
],
8+
null,
9+
[
10+
'ArrayObject' => [
11+
"\0" => [
12+
[
13+
[
14+
1,
15+
$o[0],
16+
],
17+
0,
18+
],
19+
],
20+
],
21+
'stdClass' => [
22+
'foo' => [
23+
$o[1],
24+
],
25+
],
26+
],
27+
$o[0],
28+
[]
29+
);

src/Symfony/Component/VarExporter/Tests/Fixtures/array-object.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@
66
clone $p['ArrayObject'],
77
],
88
null,
9+
[],
10+
$o[0],
911
[
10-
'ArrayObject' => [
11-
"\0" => [
12-
[
13-
[
14-
1,
15-
$o[0],
16-
],
17-
0,
18-
],
12+
[
13+
0,
14+
[
15+
1,
16+
$o[0],
1917
],
20-
],
21-
'stdClass' => [
22-
'foo' => [
23-
$o[1],
18+
[
19+
'foo' => $o[1],
2420
],
2521
],
26-
],
27-
$o[0],
28-
[]
22+
-1 => [
23+
0,
24+
[],
25+
[],
26+
],
27+
]
2928
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
4+
$o = \Symfony\Component\VarExporter\Internal\Registry::unserialize([], [
5+
'C:54:"Symfony\\Component\\VarExporter\\Tests\\FinalArrayIterator":49:{a:2:{i:0;i:123;i:1;s:21:"x:i:0;a:0:{};m:a:0:{}";}}',
6+
]),
7+
null,
8+
[],
9+
$o[0],
10+
[]
11+
);
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
<?php
22

33
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
4-
$o = \Symfony\Component\VarExporter\Internal\Registry::unserialize([], [
5-
'C:54:"Symfony\\Component\\VarExporter\\Tests\\FinalArrayIterator":49:{a:2:{i:0;i:123;i:1;s:21:"x:i:0;a:0:{};m:a:0:{}";}}',
6-
]),
4+
$o = [
5+
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['Symfony\\Component\\VarExporter\\Tests\\FinalArrayIterator'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\FinalArrayIterator')),
6+
],
77
null,
88
[],
99
$o[0],
10-
[]
10+
[
11+
[
12+
0,
13+
[],
14+
[],
15+
],
16+
]
1117
);

0 commit comments

Comments
 (0)