Skip to content

Commit 6b4d196

Browse files
committed
[VarDump] Fix order of dumped properties - parent goes first
1 parent 86901b1 commit 6b4d196

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

Caster/Caster.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ private static function getClassProperties(\ReflectionClass $class): array
177177
$classProperties = [];
178178
$className = $class->name;
179179

180+
if ($parent = $class->getParentClass()) {
181+
$classProperties += self::$classProperties[$parent->name] ??= self::getClassProperties($parent);
182+
}
183+
180184
foreach ($class->getProperties() as $p) {
181185
if ($p->isStatic()) {
182186
continue;
@@ -189,10 +193,6 @@ private static function getClassProperties(\ReflectionClass $class): array
189193
}] = new UninitializedStub($p);
190194
}
191195

192-
if ($parent = $class->getParentClass()) {
193-
$classProperties += self::$classProperties[$parent->name] ??= self::getClassProperties($parent);
194-
}
195-
196196
return $classProperties;
197197
}
198198
}

Tests/Caster/CasterTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,29 @@ public function __debugInfo(): array
185185
}
186186
});
187187
}
188+
189+
public function testClassHierarchy()
190+
{
191+
$this->assertDumpMatchesFormat(<<<'DUMP'
192+
Symfony\Component\VarDumper\Tests\Caster\B {
193+
+a: "a"
194+
#b: "b"
195+
-c: "c"
196+
+d: "d"
197+
#e: "e"
198+
-f: "f"
199+
}
200+
DUMP, new B());
201+
}
202+
}
203+
204+
class A {
205+
public $a = 'a';
206+
protected $b = 'b';
207+
private $c = 'c';
208+
}
209+
class B extends A {
210+
public $d = 'd';
211+
protected $e = 'e';
212+
private $f = 'f';
188213
}

0 commit comments

Comments
 (0)