Skip to content

Commit

Permalink
[VarDump] Fix order of dumped properties - parent goes first
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrixx committed Oct 24, 2023
1 parent fafbbfa commit 35d0e2f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Symfony/Component/VarDumper/Caster/Caster.php
Expand Up @@ -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;
Expand All @@ -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;
}
}
27 changes: 27 additions & 0 deletions src/Symfony/Component/VarDumper/Tests/Caster/CasterTest.php
Expand Up @@ -185,4 +185,31 @@ public function __debugInfo(): array
}
});
}

public function testClassHierarchy()
{
$c = eval(<<<'PHP'
class A {
public $a = 'a';
protected $b = 'b';
private $c = 'c';
}
class B extends A {
public $d = 'd';
protected $e = 'e';
private $f = 'f';
}
return new B();
PHP);
$this->assertDumpMatchesFormat(<<<'DUMP'
B {
+a: "a"
#b: "b"
-c: "c"
+d: "d"
#e: "e"
-f: "f"
}
DUMP, $c);
}
}

0 comments on commit 35d0e2f

Please sign in to comment.