Skip to content

Commit 44d76a0

Browse files
bug #52272 [VarDump] Fix order of dumped properties - parent goes first (lyrixx)
This PR was merged into the 6.4 branch. Discussion ---------- [VarDump] Fix order of dumped properties - parent goes first | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | | Issues | | License | MIT Commits ------- 900d271a28 [VarDump] Fix order of dumped properties - parent goes first
2 parents 86901b1 + 6b4d196 commit 44d76a0

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,32 @@ 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+
{
206+
public $a = 'a';
207+
protected $b = 'b';
208+
private $c = 'c';
209+
}
210+
211+
class B extends A
212+
{
213+
public $d = 'd';
214+
protected $e = 'e';
215+
private $f = 'f';
188216
}

0 commit comments

Comments
 (0)