From 0132ba9dc5554a6227480cb8b755d557b8143ba9 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 2 Dec 2018 00:05:18 +0100 Subject: [PATCH] [VarExporter] fix dumping protected property from abstract classes --- .../Component/VarExporter/Internal/Exporter.php | 3 +-- .../Tests/Fixtures/abstract-parent.php | 17 +++++++++++++++++ .../VarExporter/Tests/Fixtures/final-error.php | 2 +- .../VarExporter/Tests/Fixtures/private.php | 6 +++++- .../VarExporter/Tests/VarExporterTest.php | 15 +++++++++++++++ 5 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 src/Symfony/Component/VarExporter/Tests/Fixtures/abstract-parent.php diff --git a/src/Symfony/Component/VarExporter/Internal/Exporter.php b/src/Symfony/Component/VarExporter/Internal/Exporter.php index bbb409e194c25..563eadc8c4d66 100644 --- a/src/Symfony/Component/VarExporter/Internal/Exporter.php +++ b/src/Symfony/Component/VarExporter/Internal/Exporter.php @@ -125,8 +125,7 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount $c = 'stdClass'; } elseif ('*' === $n[1]) { $n = substr($n, 3); - $c = $reflector->getProperty($n)->class; - if ('Error' === $c) { + if ('Error' === $c = $class) { $c = 'TypeError'; } elseif ('Exception' === $c) { $c = 'ErrorException'; diff --git a/src/Symfony/Component/VarExporter/Tests/Fixtures/abstract-parent.php b/src/Symfony/Component/VarExporter/Tests/Fixtures/abstract-parent.php new file mode 100644 index 0000000000000..5548b9f8c8d25 --- /dev/null +++ b/src/Symfony/Component/VarExporter/Tests/Fixtures/abstract-parent.php @@ -0,0 +1,17 @@ + [ + 'foo' => [ + 123, + ], + ], + ], + $o[0], + [] +); diff --git a/src/Symfony/Component/VarExporter/Tests/Fixtures/final-error.php b/src/Symfony/Component/VarExporter/Tests/Fixtures/final-error.php index dc260dc0242c5..78da25114122c 100644 --- a/src/Symfony/Component/VarExporter/Tests/Fixtures/final-error.php +++ b/src/Symfony/Component/VarExporter/Tests/Fixtures/final-error.php @@ -6,7 +6,7 @@ ]), null, [ - 'TypeError' => [ + 'Symfony\\Component\\VarExporter\\Tests\\FinalError' => [ 'file' => [ \dirname(__DIR__).\DIRECTORY_SEPARATOR.'VarExporterTest.php', ], diff --git a/src/Symfony/Component/VarExporter/Tests/Fixtures/private.php b/src/Symfony/Component/VarExporter/Tests/Fixtures/private.php index a9e28416e54c8..a901afe6eac9d 100644 --- a/src/Symfony/Component/VarExporter/Tests/Fixtures/private.php +++ b/src/Symfony/Component/VarExporter/Tests/Fixtures/private.php @@ -10,13 +10,17 @@ 'Symfony\\Component\\VarExporter\\Tests\\MyPrivateValue' => [ 'prot' => [ 123, - 123, ], 'priv' => [ 234, 234, ], ], + 'Symfony\\Component\\VarExporter\\Tests\\MyPrivateChildValue' => [ + 'prot' => [ + 1 => 123, + ], + ], ], [ $o[0], diff --git a/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php b/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php index f5096176868ad..c88f445b769bc 100644 --- a/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php +++ b/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php @@ -192,6 +192,8 @@ public function provideExport() $value->bis = new \ReflectionClass($value); yield array('wakeup-refl', $value); + + yield array('abstract-parent', new ConcreteClass()); } } @@ -320,3 +322,16 @@ public function __clone() throw new \BadMethodCallException('Should not be called.'); } } + +abstract class AbstractClass +{ + protected $foo; +} + +class ConcreteClass extends AbstractClass +{ + public function __construct() + { + $this->foo = 123; + } +}