From 6b4d19674013ce1c0728125ca69c64269417fa4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Tue, 24 Oct 2023 16:50:56 +0200 Subject: [PATCH] [VarDump] Fix order of dumped properties - parent goes first --- Caster/Caster.php | 8 ++++---- Tests/Caster/CasterTest.php | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Caster/Caster.php b/Caster/Caster.php index e79ee73..d50a3df 100644 --- a/Caster/Caster.php +++ b/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/Tests/Caster/CasterTest.php b/Tests/Caster/CasterTest.php index 70e7436..0baf8f2 100644 --- a/Tests/Caster/CasterTest.php +++ b/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'; }