Skip to content

Commit 3d44c7f

Browse 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

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

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

Lines 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

Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy