10BC0 [VarExporter] fix dumping private properties from abstract classes · symfony/symfony@b10e263 · GitHub
[go: up one dir, main page]

Skip to content

Commit b10e263

Browse files
[VarExporter] fix dumping private properties from abstract classes
1 parent 4548a44 commit b10e263

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
125125
$c = 'stdClass';
126126
} elseif ('*' === $n[1]) {
127127
$n = substr($n, 3);
128-
if ('Error' === $c = $class) {
128+
$c = $reflector->getProperty($n)->class;
129+
if ('Error' === $c) {
129130
$c = 'TypeError';
130131
} elseif ('Exception' === $c) {
131132
$c = 'ErrorException';

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\VarExporter\Internal;
1313

14+
use Symfony\Component\VarExporter\Exception\ClassNotFoundException;
15+
1416
/**
1517
* @author Nicolas Grekas <p@tchwork.com>
1618
*
@@ -59,7 +61,10 @@ public static function getHydrator($class)
5961
};
6062
}
6163

62-
$classReflector = Registry::$reflectors[$class] ?? Registry::getClassReflector($class);
64+
if (!\class_exists($class) && !\interface_exists($class, false) && !\trait_exists($class, false)) {
65+
throw new ClassNotFoundException($class);
66+
}
67+
$classReflector = new \ReflectionClass($class);
6368

6469
if (!$classReflector->isInternal()) {
6570
return self::$hydrators[$class] = (self::$hydrators['stdClass'] ?? self::getHydrator('stdClass'))->bindTo(null, $class);

src/Symfony/Component/VarExporter/Tests/Fixtures/abstract-parent.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
],
77
null,
88
[
9-
'Symfony\\Component\\VarExporter\\Tests\\ConcreteClass' => [
9+
'Symfony\\Component\\VarExporter\\Tests\\AbstractClass' => [
1010
'foo' => [
1111
123,
1212
],
13+
'bar' => [
14+
234,
15+
],
1316
],
1417
],
1518
$o[0],

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

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

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@
1010
'Symfony\\Component\\VarExporter\\Tests\\MyPrivateValue' => [
1111
'prot' => [
1212
123,
13+
123,
1314
],
1415
'priv' => [
1516
234,
1617
234,
1718
],
1819
],
19-
'Symfony\\Component\\VarExporter\\Tests\\MyPrivateChildValue' => [
20-
'prot' => [
21-
1 => 123,
22-
],
23-
],
2420
],
2521
[
2622
$o[0],

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,19 @@ public function __clone()
326326
abstract class AbstractClass
327327
{
328328
protected $foo;
329+
private $bar;
330+
331+
protected function setBar($bar)
332+
{
333+
$this->bar = $bar;
334+
}
329335
}
330336

331337
class ConcreteClass extends AbstractClass
332338
{
333339
public function __construct()
334340
{
335341
$this->foo = 123;
342+
$this->setBar(234);
336343
}
337344
}

0 commit comments

Comments
 (0)
0