Skip to content

Commit 4713537

Browse files
bug #29418 [VarExporter] fix dumping protected property from abstract classes (nicolas-grekas)
This PR was merged into the 4.2 branch. Discussion ---------- [VarExporter] fix dumping protected property from abstract classes | Q | A | ------------- | --- | Branch? | 4.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #29406 | License | MIT | Doc PR | - Commits ------- 0132ba9 [VarExporter] fix dumping protected property from abstract classes
2 parents 3fe3d4e + 0132ba9 commit 4713537

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
125125
$c = 'stdClass';
126126
} elseif ('*' === $n[1]) {
127127
$n = substr($n, 3);
128-
$c = $reflector->getProperty($n)->class;
129-
if ('Error' === $c) {
128+
if ('Error' === $c = $class) {
130129
$c = 'TypeError';
131130
} elseif ('Exception' === $c) {
132131
$c = 'ErrorException';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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\\ConcreteClass'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\ConcreteClass')),
6+
],
7+
null,
8+
[
9+
'Symfony\\Component\\VarExporter\\Tests\\ConcreteClass' => [
10+
'foo' => [
11+
123,
12+
],
13+
],
14+
],
15+
$o[0],
16+
[]
17+
);

src/Symfony/Component/VarExporter/Tests/Fixtures/final-error.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
]),
77
null,
88
[
9-
'TypeError' => [
9+
'Symfony\\Component\\VarExporter\\Tests\\FinalError' => [
1010
'file' => [
1111
\dirname(__DIR__).\DIRECTORY_SEPARATOR.'VarExporterTest.php',
1212
],

src/Symfony/Component/VarExporter/Tests/Fixtures/private.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010
'Symfony\\Component\\VarExporter\\Tests\\MyPrivateValue' => [
1111
'prot' => [
1212
123,
13-
123,
1413
],
1514
'priv' => [
1615
234,
1716
234,
1817
],
1918
],
19+
'Symfony\\Component\\VarExporter\\Tests\\MyPrivateChildValue' => [
20+
'prot' => [
21+
1 => 123,
22+
],
23+
],
2024
],
2125
[
2226
$o[0],

src/Symfony/Component/VarExporter/Tests/VarExporterTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ public function provideExport()
192192
$value->bis = new \ReflectionClass($value);
193193

194194
yield array('wakeup-refl', $value);
195+
196+
yield array('abstract-parent', new ConcreteClass());
195197
}
196198
}
197199

@@ -320,3 +322,16 @@ public function __clone()
320322
throw new \BadMethodCallException('Should not be called.');
321323
}
322324
}
325+
326+
abstract class AbstractClass
327+
{
328+
protected $foo;
329+
}
330+
331+
class ConcreteClass extends AbstractClass
332+
{
333+
public function __construct()
334+
{
335+
$this->foo = 123;
336+
}
337+
}

0 commit comments

Comments
 (0)