Skip to content

Commit d07dae5

Browse files
Merge branch '4.3' into 4.4
* 4.3: fix deps=low [VarExporter] fix support for PHP 7.4 Use PHP 7.4 on deps=low
2 parents 1de0845 + d5b4e2d commit d07dae5

15 files changed

+201
-64
lines changed

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:{}';

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+
);

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+
);

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+
);

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
);

Tests/Fixtures/final-error-legacy.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
4+
$o = \Symfony\Component\VarExporter\Internal\Registry::unserialize([], [
5+
'O:46:"Symfony\\Component\\VarExporter\\Tests\\FinalError":1:{s:12:"'."\0".'Error'."\0".'trace";a:0:{}}',
6+
]),
7+
null,
8+
[
9+
'TypeError' => [
10+
'file' => [
11+
\dirname(__DIR__).\DIRECTORY_SEPARATOR.'VarExporterTest.php',
12+
],
13+
'line' => [
14+
123,
15+
],
16+
],
17+
'Error' => [
18+
'trace' => [
19+
[],
20+
],
21+
],
22+
],
23+
$o[0],
24+
[
25+
1 => 0,
26+
]
27+
);

Tests/Fixtures/final-error.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

33
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
4-
$o = \Symfony\Component\VarExporter\Internal\Registry::unserialize([], [
5-
'O:46:"Symfony\\Component\\VarExporter\\Tests\\FinalError":1:{s:12:"'."\0".'Error'."\0".'trace";a:0:{}}',
6-
]),
4+
$o = [
5+
(\Symfony\Component\VarExporter\Internal\Registry::$factories['Symfony\\Component\\VarExporter\\Tests\\FinalError'] ?? \Symfony\Component\VarExporter\Internal\Registry::f('Symfony\\Component\\VarExporter\\Tests\\FinalError'))(),
6+
],
77
null,
88
[
99
'TypeError' => [
@@ -14,6 +14,11 @@
1414
123,
1515
],
1616
],
17+
'Error' => [
18+
'trace' => [
19+
[],
20+
],
21+
],
1722
],
1823
$o[0],
1924
[
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
4+
$o = [
5+
clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['SplObjectStorage'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('SplObjectStorage')),
6+
clone ($p['stdClass'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('stdClass')),
7+
],
8+
null,
9+
[
10+
'SplObjectStorage' => [
11+
"\0" => [
12+
[
13+
$o[1],
14+
345,
15+
],
16+
],
17+
],
18+
],
19+
$o[0],
20+
[]
21+
);

Tests/Fixtures/spl-object-storage.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
clone ($p['stdClass'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('stdClass')),
77
],
88
null,
9+
[],
10+
$o[0],
911
[
10-
'SplObjectStorage' => [
11-
"\0" => [
12-
[
13-
$o[1],
14-
345,
15-
],
12+
[
13+
[
14+
$o[1],
15+
345,
1616
],
17+
[],
1718
],
18-
],
19-
$o[0],
20-
[]
19+
]
2120
);

Tests/VarExporterTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\VarExporter\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use PHPUnit\Framework\Warning;
1615
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
1716
use Symfony\Component\VarExporter\Internal\Registry;
1817
use Symfony\Component\VarExporter\VarExporter;
@@ -76,10 +75,6 @@ public function provideFailingSerialization()
7675
*/
7776
public function testExport(string $testName, $value, bool $staticValueExpected = false)
7877
{
79-
if (\PHP_VERSION_ID >= 70400 && \in_array($testName, ['spl-object-storage', 'array-object-custom', 'array-iterator', 'array-object', 'final-array-iterator'])) {
80-
throw new Warning('PHP 7.4 breaks this test.');
81-
}
82-
8378
$dumpedValue = $this->getDump($value);
8479
$isStaticValue = true;
8580
$marshalledValue = VarExporter::export($value, $isStaticValue);
@@ -91,7 +86,12 @@ public function testExport(string $testName, $value, bool $staticValueExpected =
9186

9287
$dump = "<?php\n\nreturn ".$marshalledValue.";\n";
9388
$dump = str_replace(var_export(__FILE__, true), "\\dirname(__DIR__).\\DIRECTORY_SEPARATOR.'VarExporterTest.php'", $dump);
94-
$fixtureFile = __DIR__.'/Fixtures/'.$testName.'.php';
89+
90+
if (\PHP_VERSION_ID < 70400 && \in_array($testName, ['array-object', 'array-iterator', 'array-object-custom', 'spl-object-storage', 'final-array-iterator', 'final-error'], true)) {
91+
$fixtureFile = __DIR__.'/Fixtures/'.$testName.'-legacy.php';
92+
} else {
93+
$fixtureFile = __DIR__.'/Fixtures/'.$testName.'.php';
94+
}
9595
$this->assertStringEqualsFile($fixtureFile, $dump);
9696

9797
if ('incomplete-class' === $testName || 'external-references' === $testName) {

0 commit comments

Comments
 (0)