diff --git a/src/Symfony/Component/VarDumper/Caster/Caster.php b/src/Symfony/Component/VarDumper/Caster/Caster.php index e79ee735fb54b..d50a3dfadfdaf 100644 --- a/src/Symfony/Component/VarDumper/Caster/Caster.php +++ b/src/Symfony/Component/VarDumper/Caster/Caster.php @@ -177,6 +177,10 @@ private static function getClassProperties(\ReflectionClass $class): array $classProperties = []; $className = $class->name; + if ($parent = $class->getParentClass()) { + $classProperties += self::$classProperties[$parent->name] ??= self::getClassProperties($parent); + } + foreach ($class->getProperties() as $p) { if ($p->isStatic()) { continue; @@ -189,10 +193,6 @@ private static function getClassProperties(\ReflectionClass $class): array }] = new UninitializedStub($p); } - if ($parent = $class->getParentClass()) { - $classProperties += self::$classProperties[$parent->name] ??= self::getClassProperties($parent); - } - return $classProperties; } } diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/CasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/CasterTest.php index 70e7436176afb..0baf8f21fa3eb 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/CasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/CasterTest.php @@ -185,4 +185,29 @@ public function __debugInfo(): array } }); } + + public function testClassHierarchy() + { + $this->assertDumpMatchesFormat(<<<'DUMP' + Symfony\Component\VarDumper\Tests\Caster\B { + +a: "a" + #b: "b" + -c: "c" + +d: "d" + #e: "e" + -f: "f" + } + DUMP, new B()); + } +} + +class A { + public $a = 'a'; + protected $b = 'b'; + private $c = 'c'; +} +class B extends A { + public $d = 'd'; + protected $e = 'e'; + private $f = 'f'; }