Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3d44c7f

Browse filesBrowse files
committed
bug #26999 [VarDumper] Fix dumping of SplObjectStorage (corphi)
This PR was squashed before being merged into the 2.7 branch (closes #26999). Discussion ---------- [VarDumper] Fix dumping of SplObjectStorage | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - This is a bug fix for dumping instances of `SplObjectStorage`. The bug was introduced in #23176, by fixing that the internal pointer was changed upon dumping. I added tests for both issues. Commits ------- b2ac6b6 [VarDumper] Fix dumping of SplObjectStorage
2 parents b97a4ae + b2ac6b6 commit 3d44c7f
Copy full SHA for 3d44c7f

File tree

2 files changed

+22
-2
lines changed
Filter options

2 files changed

+22
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/SplCaster.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@ public static function castObjectStorage(\SplObjectStorage $c, array $a, Stub $s
8686
$storage = array();
8787
unset($a[Caster::PREFIX_DYNAMIC."\0gcdata"]); // Don't hit https://bugs.php.net/65967
8888

89-
foreach (clone $c as $obj) {
89+
$clone = clone $c;
90+
foreach ($clone as $obj) {
9091
$storage[spl_object_hash($obj)] = array(
9192
'object' => $obj,
92-
'info' => $c->getInfo(),
93+
'info' => $clone->getInfo(),
9394
);
9495
}
9596

‎src/Symfony/Component/VarDumper/Tests/Caster/SplCasterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Tests/Caster/SplCasterTest.php
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,23 @@ public function provideCastSplDoublyLinkedList()
4040
array(\SplDoublyLinkedList::IT_MODE_LIFO | \SplDoublyLinkedList::IT_MODE_DELETE, 'IT_MODE_LIFO | IT_MODE_DELETE'),
4141
);
4242
}
43+
44+
public function testCastObjectStorageIsntModified()
45+
{
46+
$var = new \SplObjectStorage();
47+
$var->attach(new \stdClass());
48+
$var->rewind();
49+
$current = $var->current();
50+
51+
$this->assertDumpMatchesFormat('%A', $var);
52+
$this->assertSame($current, $var->current());
53+
}
54+
55+
public function testCastObjectStorageDumpsInfo()
56+
{
57+
$var = new \SplObjectStorage();
58+
$var->attach(new \stdClass(), new \DateTime());
59+
60+
$this->assertDumpMatchesFormat('%ADateTime%A', $var);
61+
}
4362
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.