8000 bug #16338 [VarDumper] Fix anonymous class dumping (nicolas-grekas) · symfony/symfony@f042197 · GitHub
[go: up one dir, main page]

Skip to content

Commit f042197

Browse files
committed
bug #16338 [VarDumper] Fix anonymous class dumping (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- [VarDumper] Fix anonymous class dumping | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Follows a comment from @stof Commits ------- 65da4d5 [VarDumper] Fix anonymous class dumping
2 parents 6227409 + 65da4d5 commit f042197

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/Symfony/Component/VarDumper/Caster/Caster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static function castObject($obj, \ReflectionClass $reflector)
5555
if (!isset($k[0]) || ("\0" !== $k[0] && !$reflector->hasProperty($k))) {
5656
$p[$i] = self::PREFIX_DYNAMIC.$k;
5757
} elseif (isset($k[16]) && "\0" === $k[16] && 0 === strpos($k, "\0class@anonymous\0")) {
58-
$p[$i] = "\0anonymous-".$reflector->name.strrchr($k, "\0");
58+
$p[$i] = "\0".$reflector->getParentClass().'@anonymous'.strrchr($k, "\0");
5959
}
6060
}
6161
$a = array_combine($p, $a);

src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,24 +209,22 @@ protected function castObject(Stub $stub, $isNested)
209209
$class = $stub->class;
210210

211211
if (isset($class[15]) && "\0" === $class[15] && 0 === strpos($class, "class@anonymous\x00")) {
212-
$class = get_parent_class($class);
213-
$stub->class = 'anonymous-'.$class;
212+
$stub->class = get_parent_class($class).'@anonymous';
214213
}
215214
if (isset($this->classInfo[$class])) {
216215
$classInfo = $this->classInfo[$class];
217216
} else {
218217
$classInfo = array(
219-
$class,
220218
new \ReflectionClass($class),
221219
array_reverse(array($class => $class) + class_parents($class) + class_implements($class) + array('*' => '*')),
222220
);
223221

224222
$this->classInfo[$class] = $classInfo;
225223
}
226224

227-
$a = $this->callCaster('Symfony\Component\VarDumper\Caster\Caster::castObject', $obj, $classInfo[1], null, $isNested);
225+
$a = $this->callCaster('Symfony\Component\VarDumper\Caster\Caster::castObject', $obj, $classInfo[0], null, $isNested);
228226

229-
foreach ($classInfo[2] as $p) {
227+
foreach ($classInfo[1] as $p) {
230228
if (!empty($this->casters[$p = strtolower($p)])) {
231229
foreach ($this->casters[$p] as $p) {
232230
$a = $this->callCaster($p, $obj, $a, $stub, $isNested);

src/Symfony/Component/VarDumper/Tests/Caster/CasterTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,18 @@ public function testAnonymousClass()
157157

158158
$this->assertDumpMatchesFormat(
159159
<<<'EOTXT'
160-
anonymous-stdClass {
160+
stdClass@anonymous {
161+
-foo: "foo"
162+
}
163+
EOTXT
164+
, $c
165+
);
166+
167+
$c = eval('return new class { private $foo = "foo"; };');
168+
169+
$this->assertDumpMatchesFormat(
170+
<<<'EOTXT'
171+
@anonymous {
161172
-foo: "foo"
162173
}
163174
EOTXT

0 commit comments

Comments
 (0)
0